如果不使用多态机制,那么通过基类的指针虽然可以指向派生类对象,但是只能访问从基类继承的成员。有如下程序,没有使用多态机制 #include <iostream> using namespace std; class Base{ int a,b; public: Base(int x,int y){ a=x; b=y;} void show(){ cout< </iostream> </"a_vfun></iostream.h> </endl;> </":></p.gettype()> </iostream> </string.h> </"fun1testclass"<></iostream></”class></”class></(++a)></iostream></类名></函数返回值></iostream.h></endl></’\t’<<></aobj.geta()></iostream.h></iostream></iostream></iostream></num;}></iostream.h></endl;> </'\t'<></iostream.h></iostream.h></"base::fun"<></iostream.h></"bb";></iostream.h></"a1";}></iostream.h></c;></iostream.h></1;></iostream> </'1';></iostream></"base></iostream.h></"a";}></iostream.h></"0";}></iostream.h></""1"";}></iostream.h></endl;}></’,’;}></x></iostream> </”class></iostream.h> </""\ndrv_pri></iostream.h> </iostream> </"base::fun"<></’a';}></iomanip></iostream> </endl;></point::number></iostream> </a.get(></iostream></iostream></"1";></string.h></iostream.h> </endl;></"count="<></iostream.h></endl;> <<’,’<<b>< <endl;} }; derived:public base { int c,d; public: derived(int x,int y,int z,int m): base(x,y){c="z" ; d="m;}" void show(){ main() b1(50,50),*pb; derived d1(10,20,30,40); pb="&D1;" pb-> show(); return 0; } 运行后输出的结果是( )
A、10,20
B、30,40
C、20,30
D、50,50