#include <iostream>
using namespace std;
class Parent
{
public:
Parent() {}
virtual void foo() { cout << "My favorite song is:"; bar(); }
virtual void bar() {}
};
class Child : public Parent
{
public:
Child() : Parent() {}
virtual void bar() { cout << "Singing in the Rain"; }
void baz() { Parent::foo(); }
};
int main()
{
Child().baz(); // Outputs "My favorite song is: Singing in the Rain"
return 0;
}
答案是肯定的。上面的代码按预期工作。