0
#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 ?

Amber Roxanna
  • 1,665
  • 4
  • 24
  • 30
  • possible duplicate of [C++ superclass constructor calling rules](http://stackoverflow.com/questions/120876/c-superclass-constructor-calling-rules) Your answer is literally in the first sample. – WhozCraig Nov 17 '13 at 19:06

2 Answers2

2
Auto::Auto (string t, int w, bool e, string b, int y)
:
   Vehicle (t, w, e),
   brand (b),
   year (y)
{}
David Hammen
  • 32,454
  • 9
  • 60
  • 108
  • @uk4321 - Fixed that, thanks! I omitted the space before the first open parenthesis :) – David Hammen Nov 17 '13 at 19:16
  • Uh yeah... great job. – uk4321 Nov 17 '13 at 19:16
  • 1
    I don't like long lines. I view `Auto::Auto(string t,int w, bool e, string b, int y):Vehicle(t,w,e),brand(b),year(y){}` as an atrocity, along the lines of `int i,j,k,l,m,n,o, …, kitchen_sink;` My style reflects that. – David Hammen Nov 17 '13 at 19:19
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){}

};
Santosh Sahu
  • 2,134
  • 6
  • 27
  • 51