b4k*_*ncs 0 c++ inheritance overloading
鉴于代码:
class A{
public:
void callFirst()
{
callSecond();
}
void callSecond()
{
cout << "This an object of class A." << endl;
}
};
class B : public A{
public:
void callSecond()
{
cout << "This is an object of class B." << endl;
}
};
int main()
{
B b;
b.callFirst();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到输出:
This an object of class A.
Run Code Online (Sandbox Code Playgroud)
我可以这样做,当我调用派生类的继承方法时,它不会反过来调用基类的方法而不是重载方法,除了重载第一个方法?