#include"iostream"
using namespace std;
class A
{
public:
virtual void f(){
cout<<"A::f()"<<endl;
}
void f()const{
cout<<"A::f() const"<<endl;
}
};
class B: public A
{
public:
void f(){
cout<<"B::f()"<<endl;
}
void f()const{
cout<<"B::f() const"<<endl;
}
};
void g(const A* a)
{
a->f();
} int main()
{
A* a=new B();
a->f();
g(a);
delete a;
system("pause");
return 0;
}
求解 g(a)输出为什么是A::f() const
当将函数g(const A*a)中const 去掉是输出结果为B::f()
千巷猫影
ITMISS
相关分类