为了访问公有派生类的特定成员,可以通过讲基类指针显示转换为派生类指针. 也可以将基类的非静态成员函数定义为虚函数(在函数前加上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…
c++中,当继承结构中含有虚基类时,在构造对象时编译器会通过将一个标志位置1(表示调用虚基类构造函数),或者置0(表示不调用虚基类构造函数)来防止重复构造虚基类子对象.如下图菱形结构所示: 当构造类Bottom对象时,Bottom构造函数里面的c++伪码如下(单考虑标志位,不考虑其他): //Bottom构造函数伪码 flag = ;//标志位 if (flag) { 调用虚基类Top的构造函数 } flag = ;//标志位清零 调用Left的构造函数 flag = ;//标志位清零 调用Ri…