子类如何使用子类的相同方法名称调用超类的方法?

时间:2011-06-09 01:41:38

标签: c++

#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;
}

2 个答案:

答案 0 :(得分:15)

suzie.Person::sing();

答案 1 :(得分:2)

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

请参阅http://bobobobo.wordpress.com/2009/05/20/equivalent-of-keyword-base-in-c/以获得更好的解释。

相关问题