#include<iostream>
#include<stdlib.h>
#include<unistd.h>
#include<stdio.h>
using namespace std;
class B0
{
public:
virtual void display() //虚函数
{
cout<<"B0 display"<<endl;
}
};
class B1:public B0
{
public:
void display()
{
cout<<"B1 display"<<endl;
}
};
class B2:public B1
{
public:
void display()
{
cout<<"B2 display"<<endl;
}
};
int main()
{
B0 b,*p0;
p0=&b;
p0->display();
B1 b1;
p0=&b1;
p0->display();
B2 b2;
p0=&b2;
p0->display();
/*B2* b2;
b2->display();
b2->B1::display();
b2->B0::display();*/
return 0;
}
网友评论