#include<iostream>
using namespace std;
class A
{
public:
int a;
virtual void Print();
void Q();
};
void A::Print()
{
cout<<"A";
}
void A::Q()
{
A::Print();
}
class B:public A
{
public:
int b;
void P();
void Print();
};
void B::P()
{
A::Print();
}
void B::Print()
{
cout<<"B";
}
int main()
{
B *b=new B();
A *a=static_cast<A*>(b);
a->Q();
return 0;
}
加上::操作符可避免动态绑定
C++总是能让我想起什么(8)——访问基类函数
最新推荐文章于 2024-09-11 17:00:37 发布