Polymorphism newbie question
Hi,
I am trying to create an object which contains data members from the base class and the inherited class.
vehicle.h:
Code:
#include <iostream>
using namespace std;
class Vehicle
{
public:
void EnterNewVehicle()
{
cout << "Inside Vehicle class" << endl;
}
private:
int m_MPG;
};
class Car : public Vehicle
{
public:
private:
int m_NoOfDoors;
};
main.cpp:
Code:
#include <iostream>
#include "vehicle.h"
using namespace std;
int main()
{
int choice = 0;
cout << "Enter 1 to create a car" << endl;
cin >> choice;
switch(choice)
{
case 1:
//Create an object of type Car
Vehicle node;
//I need to create a Car object with data members from both Vehicle and Car
node.EnterNewVehicle();
case 2:
break;
}
system ("PAUSE");
return 0;
}
So I'm trying to create an object called 'node' of type Car which will have both the data members MPG and NoOfDoors.
I can ask the user for the MPG value, but don't know how to then transition into asking and entering the value for NoOfDoors.
If someone could be so kind as to tell me how this is done I'd be most grateful, but PLEASE try and explain it to me in VERY basic terms because I won't 'get it' otherwise.
Many thanks!
:)