c++ - 子类如何使用与子类相同的方法名调用父类(super class)的方法?

标签 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;
}

最佳答案

suzie.Person::sing();

关于c++ - 子类如何使用与子类相同的方法名调用父类(super class)的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6287186/

相关文章:

c++ - 错误 2 错误 C2679 : binary '/' : no operator found which takes a right-hand operand of type (or there is no acceptable conversion)

c++ - 在桌面上创建一个按钮

c++ - 如何在 Linux 上调试 native 代码时自动附加到多个子进程?

c++ - 确定外部文件中字符串的长度

c++ - 使用离散输入变量的自然域中的多对一映射?

c++ - 突然崩溃后,程序中的所有指针变量都被删除了吗?

c++ - 统计数据项时的内联代码(使用模板)

c# - 将结构列表从 C# 应用程序传递到 C++ DLL

c++ - 将数组的值成对求和,直到最终得到所有值的总和

c++ - 如何查看一个Tibco EMS独占队列是否有活跃消费者?