c++之理解多层派生
#include <iostream>
using namespace std;
class base0
{
public: void v(void){ cout<<"base0\n"; }
};
class base1:public base0{
public: virtual void v(void){ cout<<"base1\n"; }
};
class A1:public base1{
public: void v(){ cout<<"A1\n"; }
};
class A2:public A1{
public: void v(void){ cout<<"A2\n"; }
};
class B1:private base1{
public: void v(void){ cout<<"B1\n"; }
};
class B2:public B1{
public: void v(void){ cout<<"B2\n"; }
};
void main(void)
{ base1 *pb;
A1 a1;
(pb=&a1)->v();
A2 a2;
(pb=&a2)->v();
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/4c2b2be1c689bc99c667e03e7e21a3b1.png#pic_center)