新微赢技术网
标题:
[求助]多重继承的构造问题
[打印本页]
作者:
ジ↘夢衹戀
时间:
2009-11-3 02:09
标题:
[求助]多重继承的构造问题
谁能帮我改错啊,实在不知道哪里错了...
#include<iostream.h>
class vehicle
{
public:
int Maxspeed;
int Weight;
vehicle(int M,int W)
{
Maxspeed=M;
Weight=W;
} ;
void run(){cout<<"running"<<endl;};
void stop(){cout<<"stopping"<<endl;};
};
class bicycle:virtual public vehicle
{
public:
int Height;
bicycle(int M,int W,int H):vehicle(M,W)
{
Height=H;
};
};
class motorcar:virtual public vehicle
{
public:
int seatnum;
motorcar(int M,int W,int S):vehicle(M,W)
{
seatnum=S;
};
};
class Motorcycle:public bicycle,public motorcar
{
public:
Motorcycle(int H,int S):bicycly(H),mortorcar(S)
{
};
void show()
{
cout<<Maxspeed<<Weight<<Height<<seatnum;
};
};
void main()
{
}
作者:
幸福乐园
时间:
2009-11-3 02:09
我自己感觉是Motorcycle类继承的问题,就是Motorcycle构造函数这出的问题,但不知道怎么改
作者:
龍2132
时间:
2009-11-3 02:09
以下是引用janlun86在2006-5-18 18:15:00的发言:
谁能帮我改错啊,实在不知道哪里错了...
#include<iostream.h>
class vehicle
{
public:
int Maxspeed;
int Weight;
vehicle(int M,int W)
{
Maxspeed=M;
Weight=W;
} ;
void run(){cout<<"running"<<endl;};
void stop(){cout<<"stopping"<<endl;};
};
class bicycle:virtual public vehicle
{
public:
int Height;
bicycle(int M,int W,int H):vehicle(M,W)
{
Height=H;
};
};
class motorcar:virtual public vehicle
{
public:
int seatnum;
motorcar(int M,int W,int S):vehicle(M,W)
{
seatnum=S;
};
};
class Motorcycle:public bicycle,public motorcar
{
public:
Motorcycle(int H,int S,int W,int P):bicycle(H,S,W),motorcar(H,S,P),vehicle(H,S)
{
};
void show()
{
cout<<Maxspeed<<Weight<<Height<<seatnum;
};
};
void main()
{
}
作者:
兰桂枋
时间:
2009-11-3 02:09
Motorcycle(int H,int S,int W,int P):bicycle(H,S,W),motorcar(H,S,P),vehicle(H,S)
最后的初始化应该不要!
作者:
遗失ぜ的ァ美
时间:
2009-11-3 02:09
应该要吧!
作者:
水乡渔夫
时间:
2009-11-3 02:09
不应该要,在bicycle和motorcar的构造函数中已经执行了vehicle(H,S)
作者:
泡个帅滴上床
时间:
2009-11-3 02:09
以下是引用freshman42在2006-5-18 21:26:00的发言:
Motorcycle(int H,int S,int W,int P):bicycle(H,S,W),motorcar(H,S,P),vehicle(H,S)
{
};
这个我不太理解,p是什么?bicycle参数表列怎么会有W,还有motorcar,vehicle的参数表列也看不明白...请高手指教
作者:
妊嫒ぞ流逝
时间:
2009-11-3 02:09
如果按照Motorcycle(int H,int S,int W,int P):bicycle(H,S,W),motorcar(H,S,P),vehicle(H,S)
{
};
这种改法,在主函数里实例化一个对像就会出现报错error C2512: 'Motorcycle' : no appropriate default constructor available
作者:
绿茶
时间:
2009-11-3 02:09
晕,我试了下,非的要那个最后的初始化。但是不会象楼主说的那样,不能实例化啊?我可以
作者:
祗↘爲.輝仔
时间:
2009-11-3 02:09
以下是引用wfpb在2006-5-19 10:23:00的发言:
晕,我试了下,非的要那个最后的初始化。但是不会象楼主说的那样,不能实例化啊?我可以
要初始化,可以实例啊!!
欢迎光临 新微赢技术网 (http://bbs.weiying.cn/)
Powered by Discuz! X3.2