C++中私有继承公有化
2021-03-05 05:30
标签:image nbsp int include ima Speak float names str 当私有继承时,基类的所有public成员都变成了private。如果希望它们中的任何一个 是可视的,只要用派生类的public部分声明它们的名字即可: #include class Pet { class Goldfish : Pet { int main(){ C++中私有继承公有化 标签:image nbsp int include ima Speak float names str 原文地址:https://www.cnblogs.com/shiheyuanfang/p/14332672.html
using namespace std;
public:
char eat() const {return ‘a‘;}
int speak() const {return 2;}
float sleep() const {return 3.0;}
float sleep(int) const {return 4.0;}
};
public:
using Pet::eat;
using Pet::sleep;
using Pet::speak;
};
Goldfish bob;
cout cout cout cout }