子类如何使用与子类相同的方法名来调用超类的方法

How can a subclass call a method of the superclass with the same method name of the subclass?

本文关键字:方法 子类 超类 调用 何使用      更新时间:2023-10-16
#include <iostream>
using namespace std;
class Person {
public:
    void sing();
};
class Child : public Person {
public:
    void sing();
};
Person::sing() {
    cout << "Raindrops keep falling on my head..." << endl;
}
Child::sing() {
    cout << "London bridge is falling down..." << endl;
}
int main() {
    Child suzie;
    suzie.sing(); // I want to know how I can call the Person's method of sing here!
    return 0;
}
suzie.Person::sing();

孩子可以使用Person::sign()。

请参阅http://bobobobo.wordpress.com/2009/05/20/equivalent-of-keyword-base-in-c/为了一个好的解释。