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