virtual void info() {cout <<"This is a C-A-R." <<endl;};
virtual void display()
{
cout <<"Car" <<endl;
info();
}
private:
};
class Plane: virtual public Vehicle
{
public:
virtual void info() {cout <<"This is a P-L-A-N-E." <<endl;};
virtual void display()
{
cout <<"Plane" <<endl;
info();
}
private:
};
int main()
{
char goAgain('y');
enum Choice {Car=1,Plane};
int userVehicleChoice(0);
Car myCar;
Plane myPlane;
Vehicle *myVehiclePtr(0);
while (goAgain == 'y')
{
cout << "Enter 1 for car." <<endl;
cout << "Enter 2 for plane." <<endl;
cout << "Which vehicle image would you like to display?";
cin >> userVehicleChoice;
switch (userVehicleChoice)
{
case Car:
myVehiclePtr = &myCar;
break;
case Plane:
myVehiclePtr = &myPlane;
break;
default:
myVehiclePtr = 0;
}
Your classes are named Car and Plane, which is fine. But then you do this:
enum Choice {Car=1,Plane};
Which defines "Car" and "Plane" again... this time as an enum. Therefore when you come across the line:
Car myCar;
The desired result is obviously you want to make an object of type class Car -- however the compiler gets a little confused because it thinks you mean the enum Car.
The solution here is to change your enum names to something else so they don't conflict with the class names. Perhaps CAR and PLANE in the enum instead of Car and Plane -- then you should be okay (provided you change your switch statement to reflect those changes)