c++派生类构造函数_C++派生构造函数问题
#include<iostream>
#include<string>
using namespace std;
class Auto
{
public:
Auto(string t,string pro)
{
type=t;
product=pro;
}
void show()
{
cout<<"车的型号"<<type<<endl<<"车的生产商"<<product<<endl;
}
protected:
string type;
string product;
};
class Car:public Auto
{
Car(string t,string pro,int w,string c,int s,int o,int m,int l):Auto(t,pro)
{ w=weigh;
c=colour;
s=speed;
o=oil;
m=man;
l=load;}
void show1()
{
cout<<"车的型号"<<type<<endl;
cout<<"车的生产商"<<product<<endl;
cout<<"车重"<<weigh<<endl;
cout<<"颜色"<<colour<<endl;
cout<<"最高时速"<<speed<<endl;
cout<<"百公里耗油量"<<oil<<endl;
cout<<"载客数"<<man<<endl;
cout<<"载重量"<<load<<endl;
}
private:
int weigh;
string colour;
int speed;
int oil;
int man;
int load;
};
int main()
{
Car a1("跑车","兰博基尼",12,"faf",122,1,1,1);
a1.show1();
return 0;
}
这个有什么问题阿。。。求解
最佳答案
Car的构造函数前面加上public:
其他回答
暂无其它回答!