急!!!用继承写了个小程序,请高手们看看错在哪里
头文件:#ifndef LAB7_3_H
#define LAB7_3_H
#include<iostream>
using namespace std;
class vehile
{
public:
vehile();
vehile(unsigned int a);
void run();
void stop();
void showVehile();
private:
unsigned int weight;
};
class bicycle:virtual public vehile
{
public:
bicycle();
bicycle(unsigned int a,unsigned int b):vehile(a);
void showBicycle();
private:
unsigned int height;
};
class motorcar:virtual public vehile
{
public:
motorcar();
motorcar(unsigned int a,unsigned int c):vehile(a);
void showMotorcar();
private:
unsigned int seat;
};
class motorcycle:public bicycle,public motorcar
{
public:
motorcycle();
motorcycle (unsigned int a,unsigned int b,unsigned int c,unsigned int d):bicycle(a,b),motorcar(a,c),vehile(d);
void showMtorcycle();
private:
unsigned int length;
};
#endif;
方法实现文件
#include"lab7_3car.h"
vehile::vehile(unsigned int a) //车构造函数
{
weight=a;
}
void vehile::showVehile()
{
cout<<"重量:"<<weight<<endl;
}
void vehile::run()
{
cout<<"出发!!!"<<endl;
}
void vehile::stop()
{
cout<<"停止!!!"<<endl;
}
bicycle(unsigned int a,unsigned int b):vehile(a)//自行车构造函数
{
height=b;
}
void bicycle::showBicycle()
{
cout<<"高度:"<<height<<endl;
}
motorcar(unsigned int a,unsigned int c):vehile(a) //摩托车构造函数
{
seat=c;
}
void motorcar::showMotorcar()
{
cout<<"座位数:"<<seat<<endl;
}
motorcycle::motorcycle(unsigned int a,unsigned int b,unsigned int c,unsigned int d):bicycle(a,b),motorcar(a,c),vehile(d)
{
length=d;
}
void motorcycle::showMtorcycle()
{
cout<<"长度:"<<length<<endl;
}
主函数:
#include<iostream>
#include"lab7_3car.h"
using namespace std
int main()
{
motorcycle a(2,12,90,35);
cout<<"摩托车的属性如下:"<<endl;
a.showVehile();
a.showBicycle();
a.showMotorcar();
a.showMtorcycle();
cout<<"启动试车:"<<endl;
a.run();
a.stop();
}
[ 本帖最后由 softzhonghua 于 2009-11-12 19:09 编辑 ]