I have been learning C++ fairly well for the past few months in a course I'm taking, but I'm having a fair amount of difficulty creating a class. I have my first few accessor functions defined in a header, but I think that the trouble lies in the definition of the constructor I have.
In my function main(), I have an instance of my car class, auto, with arguments passed through. Yet, I recieve the error of a missing semicolon when, in fact, all lines before it have semicolons.
I have tried my book, a friend, and numerous web resources and nothing seems to make sense. Any assistance would be greatly appreciated.
I get some new errors with that change. Each of my "new" variables are coming out as undeclared. I can show what's there even with that new edit. I also get an "expected ; before } token" error at line 14, but all preceding lines have their proper semicolons.
Fixed it. I'm now working on my function, and using another webpage as a guide.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int main()
{
Car auto; //instance of class Car
int autoYear; //year of auto
string autoMake; //make of auto
int autoSpeed; //speed of auto
cout << "Enter the year model of your car. ";
cin >> autoYear;
cout << "Enter the make of your car. ";
cin >> autoMake;
auto.setYear(autoYear); //stores input year
auto.setMake(autoMake); //stores input make
}
It now says my declaration Car auto; does not declare anything. I'm also getting a bunch of "expected primary-expression before 'auto' " as well as semicolon errors.
Use something other than auto. this word is reserved or something(not sure about this). Make sure that you include "car.h" and all other required headers. You need a return statement too.
Presumably yearModel, newYearModel and make are all class members, for this to compile? You haven't shown us your class definition, so I can't be sure.