Class help!

closed account (jyU4izwU)
Hi,
I tryed compiling my code but its not working....
A little help please!

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
#include <iostream>

using namespace std;

class Student{

public:

	student();
	~student();
	int getAge();	
	void setAge(int a);

protected:
	int age;


};

Student::student(){


}

Student::~student(){

	

}

int Student::getAge(){

	return age;

}

void ::setAge(int a){

	age = a;
}

int main(){


	Student myStudent;

	myStudent.setAge(5);
	
	cout << "The student is " << myDog.getAge() << " years old!\n";

	system("pause");

	return 0;

}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
9 C:\Users\X200\Documents\C++ Project\Item.cpp ISO C++ forbids declaration of `student' with no type 
--
10 C:\Users\X200\Documents\C++ Project\Item.cpp expected class-name before '(' token 
--
20 C:\Users\X200\Documents\C++ Project\Item.cpp ISO C++ forbids declaration of `student' with no type 
--
25 C:\Users\X200\Documents\C++ Project\Item.cpp expected class-name before '(' token 
--
25 C:\Users\X200\Documents\C++ Project\Item.cpp no `Student::~Student()' member function declared in class `Student' 
--
 C:\Users\X200\Documents\C++ Project\Item.cpp In function `void setAge(int)': 
--
39 C:\Users\X200\Documents\C++ Project\Item.cpp `age' undeclared (first use this function) 
--
  (Each undeclared identifier is reported only once for each function it appears in.) 
--
 C:\Users\X200\Documents\C++ Project\Item.cpp In function `int main()': 
--
45 C:\Users\X200\Documents\C++ Project\Item.cpp `dog' undeclared (first use this function) 
--
45 C:\Users\X200\Documents\C++ Project\Item.cpp expected `;' before "myDog" 
--
47 C:\Users\X200\Documents\C++ Project\Item.cpp `myDog' undeclared (first use this function) 


Thank you...
Last edited on
closed account (jyU4izwU)
Bump...
Your constructor should have the same name as your class.

Your destructor should have the same name as your class, prefixed by ~.
Topic archived. No new replies allowed.