class A
{
public:
A()
{
}
~A()
{
}
virtual void display()
{
cout << "class A." << endl;
}
};
class B : public A
{
public:
B()
{
}
~B()
{
}
virtual void display()
{
cout << "class B." << endl;
}
void additional()
{
cout << "additional function." << endl;
}
};
int main()
{
A a;
B b;
a = b;//这样会截断 a的地址指向a的函数表。这里和java复制上转型不一样。
a.display();//打印class A.
A * pA = new B();
pA->display();//上转型,打印class B.
return 0;
}