|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
派生一个摩托车类时,在构造函数中写上motorcycle(float m, float w, float h, int s): bicycle(m, w, h),motorcar(m, w, s)//在此句后面加上float(w,m) 然后会报错
error C2614: 'motorcycle' : illegal member initialization: 'vehicle' is not a base or member
#include<iostream>
using namespace std;
class vehicle
{
public:
vehicle(float w,float m) //创建一个vehicle类
{
weight=w;
maxspeed=m;
cout<<"这辆车的最大速度为:"<<maxspeed<<endl;
cout<<"这辆车的重量为:"<<weight<<endl;
}
run();
stop();
private:float weight, maxspeed;
};
vehicle::run() //vehicle的成员函数
{
cout<<"车已启动。。。。。。"<<endl;
}
vehicle::stop() //vehicle的成员函数
{
cout<<"车已停了!"<<endl;
}
class bicycle:public vehicle //创造一个单车类
{
public:
bicycle(float w,float m,float h):vehicle(w,m)
{
height=h;
cout<<"这辆车的高度为:"<<height<<endl;
}
private:float height;
};
class motorcar:public vehicle //创造一个汽车类
{
public:
motorcar(float w,float m,int s):vehicle(w,m)
{
seatnum=s;
cout<<"这辆车能载的人数为:"<<seatnum<<endl;
}
private:int seatnum;
};
class motorcycle: public bicycle, public motorcar//创造一个摩托车类。。。
{
public:
motorcycle(float m, float w, float h, int s): bicycle(m, w, h),motorcar(m, w, s)//在此句后面加上float(w,m) 然后会报错
{ }
};
int main()
{
motorcar car(100,150,7);
car.run();
car.stop();
bicycle cle(15,10,1.20);
cle.run();
cle.stop();
motorcycle cycle(50,100,2,1);
return 0;
}
这是我在写程序上遇到的问题,想问问这是什么原因。。。。。。。。。。。。。 |
|