A bunch of errors. cpp & .h

Here are the errors I am getting...

Error 1 error C2146: syntax error : missing ';' before identifier 'make' c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car.h 9
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car.h 9
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car.h 9
Error 4 error C2061: syntax error : identifier 'String' c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car.h 13
Error 5 error C2146: syntax error : missing ';' before identifier 'getMake' c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car.h 16
Error 6 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car.h 16
Error 7 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car.h 16
Warning 8 warning C4183: 'getMake': missing return type; assumed to be a member function returning 'int' c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car.h 16
Error 9 error C2511: 'void Car::setMake(std::string)' : overloaded member function not found in 'Car' c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car class.cpp 15
Error 10 error C2065: 'year' : undeclared identifier c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car class.cpp 26
Error 11 error C2065: 'make' : undeclared identifier c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car class.cpp 31
Error 12 error C2065: 'Speed' : undeclared identifier c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car class.cpp 41
Error 13 error C2065: 'Speed' : undeclared identifier c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car class.cpp 41
Error 14 error C2065: 'Speed' : undeclared identifier c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car class.cpp 46
Error 15 error C2065: 'Speed' : undeclared identifier c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car class.cpp 46
Error 16 error C2065: 'carYear' : undeclared identifier c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car class.cpp 53
Error 17 error C2065: 'carMake' : undeclared identifier c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car class.cpp 53
Error 18 error C3861: 'displayInfo': identifier not found c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car class.cpp 77
19 IntelliSense: declaration is incompatible with "void Car::setMake(<error-type>)" (declared at line 13 of "c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\Car.h") c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car class.cpp 14
20 IntelliSense: identifier "year" is undefined c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car class.cpp 26
21 IntelliSense: declaration is incompatible with "<error-type> Car::getMake() const" (declared at line 16 of "c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\Car.h") c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car class.cpp 29
22 IntelliSense: identifier "Speed" is undefined c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car class.cpp 41
23 IntelliSense: identifier "Speed" is undefined c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car class.cpp 46
24 IntelliSense: identifier "carYear" is undefined c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car class.cpp 53
25 IntelliSense: identifier "carMake" is undefined c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car class.cpp 53
26 IntelliSense: identifier "displayInfo" is undefined c:\users\fred steinman\documents\visual studio 2010\projects\car class\car class\car class.cpp 77

Here is my header...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef CAR_H
#define CAR_H

class Car
{
	private:
		int yearModel;
		int speed;
		string make;

	public:
		void setYear(int);
		void setMake(String);
		void setSpeed(int);
		int getYear() const;
		string getMake() const;
		int getSpeed() const;
		void Accelerate();
		void Brake();
};
#endif 


Here is my source...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <iostream>
#include <string>
#include <cctype>
#include "Car.h"
using namespace std;

char again;

void Car::setYear(int y)
{
	yearModel = y;
}

void Car::setMake(string m)
{
	make = m;
}

void Car::setSpeed(int s)
{
	speed = s;
}

int Car::getYear() const
{
	return year;
}

int Car::getMake() const
{
	return make;
}

int Car::getSpeed() const
{
	return speed;
}

void Car::Accelerate()
{
	Speed = Speed+5;
}

void Car::Brake()
{
	Speed = Speed-5;
}

void dispayInfo()
{
	cout << "Current Information" << endl;
	cout << "-------------------" << endl;
	cout << carYear << " " << carMake;
	cout << "(a) Accelerate" << endl;
	cout << "(b) Brake" << endl;
	cout << "(c) End Program";
	cout << "Choice: ";
}


int main()
{
	do
	{
		Car car;
		int carYear;
		int carMake;
		int carSpeed = 0;
		char choice;

		cout << "What is the year of the car?";
		cin >> carYear;
		cout << "What is the make of the car?";
		cin >> carMake;
		do
		{
			displayInfo();
			cin >> choice;
			while(toupper(choice) < 'A' || toupper(choice) > 'C')
			{
				cout << "Choose option(A, B, C): ";
				cin >> choice;
			}

			switch (choice)
			{
				case'a':
				case'A': cout << "Car has accelerated." << endl;
					car.Accelerate();
					break;
				case'b':
				case'B': cout << "Car has braked." << endl;
					car.Brake();
					break;
			}
			cout << "Car Speed: " << car.getSpeed() << endl;
		} while (toupper(choice)!='C');
		cout << "\nDo you want to run this program again? Y/N: ";
		cin >> again;

	} while (again == 'y' || again == 'Y');

	return 0;
}

Can anyone give me a hand with this? Seems I'm in over my head.
put your includes in the header file. At this point the compiler does not know what a string is.
1) You should include <string> in Car.h. Yes, at the moment, your source file happens to include <string> before "Car.h", but that's just coincidence. "Car.h" should be usable on its own, and should include the headers it needs.

2) string is defined in the std namespace. You need to qualify the name, i.e. write std::string.

(Another possibility would be to add a "using" statement, but that's a bad idea in header files.)
Last edited on
Topic archived. No new replies allowed.