示例: #include<iostream> using namespace std; class A { public: int a; int b; A(int aa=1, int bb=2):a(aa),b(bb) {} }; class B :public A { public: B(int a=3,int b=4,int c=5,int d=6):A(a,b),d(c),g(d) {} int d; int g; }; void f(A* p,int n) { for (int i =…
为了访问公有派生类的特定成员,可以通过讲基类指针显示转换为派生类指针. 也可以将基类的非静态成员函数定义为虚函数(在函数前加上virtual) #include<iostream> using namespace std; class base{ public: /*virtual*/ void who(){ //define this function to virtual will be normal cout << "this is the class of bas…