static_cast
#include <iostream>
using namespace std;
class A {
public:
int a;
virtual void fun()
{
cout << "A:fun()" << endl;
}
};
class B:public A {
public:
int b;
virtual void fun()
{
cout << "B:fun()" << endl;
}
};
int main()
{
A obja;
B objb;
A *ptrA;
B *ptrB=&objb;
objb.fun();
ptrB->fun();
ptrA = static_cast<A*>(ptrB);
ptrA->fun();//强制类型转换结果:实现多态
cout<< "\t\t\t\t\t\t@zem" << endl;
system("pause");
return 0;
}