#include <iostream> using namespace std; class vehicle //车辆类 { private: int MaxSpeed; //最大车速 int Weight; //车重 public: vehicle(){MaxSpeed=0; Weight=0;} virtual void Run() {cout<<"A vehicle is running!"<<endl;} }; class bicycle :▁▁▁(2分) //自行车类 { private: int Height; //车高 public: bicycle(){} void Run() {cout<<"A bicycle is running!"<<endl;} }; class motorcar :▁▁▁(2分) //机动车类 { private: int SeatNum; //乘人数 public: motorcar(){} void Run() {cout << "A motorcar is running!" << endl; } }; class motorcycle:▁▁▁,▁▁▁(2分) //摩托车类 { public: motorcycle (){} void Run() {cout<<"A motorcycle is running!"<<endl;} }; int main() { motorcycle a; a.Run(); return 0; }
时间: 2024-03-21 17:42:37 浏览: 64
在 `bicycle` 类的定义中应该使用 `public` 关键字继承自 `vehicle` 类,即:
```cpp
class bicycle : public vehicle //自行车类
{
private:
int Height; //车高
public:
bicycle(){}
void Run() {cout<<"A bicycle is running!"<<endl;}
};
```
在 `motorcar` 类的定义中应该使用 `public` 关键字继承自 `vehicle` 类,即:
```cpp
class motorcar : public vehicle //机动车类
{
private:
int SeatNum; //乘人数
public:
motorcar(){}
void Run() {cout << "A motorcar is running!" << endl; }
};
```
在 `motorcycle` 类的定义中应该使用 `public` 关键字继承自 `bicycle` 类和 `motorcar` 类,即:
```cpp
class motorcycle : public bicycle, public motorcar //摩托车类
{
public:
motorcycle(){}
void Run() {cout<<"A motorcycle is running!"<<endl;}
};
```
阅读全文