Amber Roxanna
Amber Roxanna

Reputation: 1695

Using a constructor of another class

#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;
}

How do I use the constructor of the vehicle class in my Auto class ?

Upvotes: 0

Views: 81

Answers (2)

David Hammen
David Hammen

Reputation: 33116

Auto::Auto (string t, int w, bool e, string b, int y)
:
   Vehicle (t, w, e),
   brand (b),
   year (y)
{}

Upvotes: 2

Santosh Sahu
Santosh Sahu

Reputation: 2244

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){}

};

Upvotes: 1

Related Questions