64,651
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
using namespace std;
struct A
{
virtual void f(){cout<<"A"<<endl;}
};
struct B :A
{
virtual void f(){cout<<"B"<<endl;}
};
int main()
{
A* pa = new A();
pa->f();
if(B* pb = static_cast<B*>(pa))
pb->f();
return 0;
}