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

问题描述:

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

[如何通过指向派生类的基类指针调用基类方法](http://*.com/q/1136249/),[从派生类型对象上的基类调用虚方法] (http://*.com/q/2787756/)。 – outis 2012-04-22 00:17:28

suzie.Person::sing(); 
+0

或'Person&sue = suzie; sue.sing();'。 – 2011-06-09 01:45:46

+0

或'static_cast (suzie).sing();'或其任何变体,是的。 – 2011-06-09 01:46:22

+0

我写了,然后删除它。我尝试永远不会使用隐式转换将工作的演员阵容。 – 2011-06-09 01:48:30

的孩子可以使用人::征(+)。

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