|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include <iostream>
- using namespace std;
- class Car{
- public:
- Car(int wh,float we):wheel(wh),weigh(we){}
- void Getinfo(){
- cout<<"车轮数:"<<wheel<<" 车重:"<<weigh<<"t"<<endl;
- }
- protected:
- int wheel;
- float weigh;
- };
- class LCar:private Car{
- public:
- LCar(int wh,float we,int peop):wheel(wh),weigh(we),people_allow(peop){} //这里报错了 说没有weigh和wheel成员变量 不是从Car继承了吗。。。
- void Getinfo(){
- cout<<"车轮数:"<<wheel<<" 车重:"<<weigh<<"t 载客量:"<<people_allow<<"人"<<endl;
- }
- private:
- int people_allow;
-
- };
- class Truck:private Car{
- public:
- Truck(int wh,float we,int peop,float we_al):wheel(wh),weigh(we),people_allow(peop),weigh_allow(we_al){} //这里也报错了 同样的原因
- void Getinfo(){
- cout<<"车轮数:"<<wheel<<" 车重:"<<weigh<<"t 载客量:"<<people_allow<<"人 载重量:"<<weigh_allow<<"t "<<endl;
- }
- private:
- int people_allow;
- float weigh_allow;
-
- };
- int main(){
- Truck T(4,21,4,50);
- T.Getinfo()
- }
复制代码
这样写
- #include <iostream>
- using namespace std;
- class Car{
- public:
- Car(int wh,float we):wheel(wh),weigh(we){}
- void Getinfo(){
- cout<<"车轮数:"<<wheel<<" 车重:"<<weigh<<"t"<<endl;
- }
- protected:
- int wheel;
- float weigh;
- };
- class LCar:private Car{
- public:
- LCar(int wh,float we,int peop):Car(wh,we),people_allow(peop){} //这里报错了 说没有weigh和wheel成员变量 不是从Car继承了吗。。。
- void Getinfo(){
- cout<<"车轮数:"<<wheel<<" 车重:"<<weigh<<"t 载客量:"<<people_allow<<"人"<<endl;
- }
- private:
- int people_allow;
-
- };
- class Truck:private Car{
- public:
- Truck(int wh,float we,int peop,float we_al):Car(wh,we),people_allow(peop),weigh_allow(we_al){} //这里也报错了 同样的原因
- void Getinfo(){
- cout<<"车轮数:"<<wheel<<" 车重:"<<weigh<<"t 载客量:"<<people_allow<<"人 载重量:"<<weigh_allow<<"t "<<endl;
- }
- private:
- int people_allow;
- float weigh_allow;
-
- };
- int main(){
- Truck T(4,21,4,50);
- T.Getinfo();
- return 0;
- }
复制代码
|
|