#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class A
{
public:
A(){}
~A(){}
virtual void Print()
{
cout<<"A Print"<<endl;
}
};
class B: public A
{
public:
B(){}
~B(){}
void Print()
{
cout<<"B Print"<<endl;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
A *p = new A;
p->Print(); //p指向A,所以调用A中方法
p = new B;
p->Print(); //p指向B,所以调用B中方法
system("pause");
return 0;
}
输出
A Print
B Print