#include <iostream>
using namespace std;
class Vehicle{
protected:
string type;
int wheels;
int engine; // number of engines in vehicle
public:
Vehicle(string t, int w,bool e):
type(t), wheels(w), engine(e){};
void setType(string t) {type = t;}
void setWheels(int w) {wheels = w;}
void setEngine(int e) {engine = e;}
string getType(){return type;}
int getWheels() {return wheels;}
int getEngine() {return engine;}
};
class Auto:public Vehicle {
private:
string brand;
int year;
public:
Auto(string t, int w, bool e, string b, int y):
};
int main()
{
return 0;
}
如何在Auto类中使用车辆类的构造函数?
答案 0 :(得分:2)
Auto::Auto (string t, int w, bool e, string b, int y)
:
Vehicle (t, w, e),
brand (b),
year (y)
{}
答案 1 :(得分:1)
class Auto:public Vehicle {
private:
string brand;
int year;
public:
Auto(string t, int w, bool e, string b, int y):Vehicle(t,w,e){}
};