In order to get the previous list of code to compile you have to remove the line
Anyways there are lots of misconceptions in your code, this is one of those. You're actually calling the print() which is non-static member of Vehicle without referring to any object. In order to make a call to a non-static member function you always need an object to call that function from, just like you did in:
1 2
|
c.print();
mc.print();
| |
Applying the concept to a real life example, what you did there (
Vehicle.print();
) is like tying to pump up the tyres (well, this would have been a different function but you got the idea) of a non-existing vehicle, quite of an impossible task, isn't it?
This part is also quite weird:
1 2 3 4 5 6
|
cout << "Please enter the miles per gallon for vehicle:" << endl;
cin >> mpg;
Vehicle milesPerGallon(double mpg);
cout << "Please enter the number of wheels for the vehicle:" << endl;
cin >> wheelss;
Vehicle wheels(int wheelss);
| |
First of all we have some syntax problems: calling the constructor of a class is like calling any other function, furthermore
mpg
and
wheelss
have already been declared, therefore writing
Vehicle milesPerGallon(double mpg);
or
Vehicle wheels(int wheelss);
is wrong!
Instead you should have written:
1 2 3 4 5 6
|
cout << "Please enter the miles per gallon for vehicle:" << endl;
cin >> mpg;
Vehicle milesPerGallon(mpg);
cout << "Please enter the number of wheels for the vehicle:" << endl;
cin >> wheelss;
Vehicle wheels(wheelss);
| |
Anyways, apart from the syntax, there is a logical misconception here: how the heck can milesPerGallon or wheelss be vehicles? Try to think it over, that doesn't make any sense.
Hope it helped out! ;)