gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:58:39 25 4
gpt4 key购买 nike

#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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com