I DONT UNDERSTAND THIS!!!! need answers

Here is syntax, everything seems 100% correct and yet it doesn't wanna recognize my objects. Help please:

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

class Vehicle
{
public:

void setMake() {cout <<"Enter make of vehicle: " <<endl; cin >> make;};
void setModel() {cout <<"Enter vehicle model: " <<endl; cin >> model;};
string getMake() {return make;};
string getModel() {return model;};
virtual void info() {cout << "This is a vehicle." << endl;};
virtual void display() = 0;

private:

string make;
string model;
};

class Car: virtual public Vehicle
{
public:

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

if (myVehiclePtr)
{
myVehiclePtr->display();
myVehiclePtr->info();
}
else
{
cout << endl << endl << "Invalid input." << endl << endl << endl;
}

cout << "Do you want to go again (y/n)?";
cin >> goAgain;
system("cls");
}

return 0;
}

Keeps giving me the FOLLOWING 6 errors:

Error 3 error C2146: syntax error : missing ';' before identifier 'myPlane' c:\users\edgar\documents\visual studio 2008\projects\lab3\lab3\main.cpp 66
Error 1 error C2146: syntax error : missing ';' before identifier 'myCar' c:\users\edgar\documents\visual studio 2008\projects\lab3\lab3\main.cpp 65
Error 4 error C2065: 'myPlane' : undeclared identifier c:\users\edgar\documents\visual studio 2008\projects\lab3\lab3\main.cpp 66
Error 6 error C2065: 'myPlane' : undeclared identifier c:\users\edgar\documents\visual studio 2008\projects\lab3\lab3\main.cpp 82
Error 2 error C2065: 'myCar' : undeclared identifier c:\users\edgar\documents\visual studio 2008\projects\lab3\lab3\main.cpp 65
Error 5 error C2065: 'myCar' : undeclared identifier c:\users\edgar\documents\visual studio 2008\projects\lab3\lab3\main.cpp 79



Thanks in advance!
Last edited on
In the future please use code tags.

[code]
paste your code here
[/code]

As for your problem:

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)
Last edited on
You have an enum and a class called Car.
Typical newbie mistake, to blame the compiler.
Fixed!

Thanks guys
Also - what's with the virtual inheritance?
For example - why class Car: virtual public Vehicle ?
Topic archived. No new replies allowed.