Class method in a vector call

I keep getting some errors on this code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#pragma once
#include"Include.h" //Here I have #include<vector>, using namespace std, 
                    //#include "schClass" 

class schClass;

class school
{
public:
        //other methods
	void addClass(class schClass& newClass);
	void test(void){ cout << section[0].year() << section[0].section(); } //C2027 & C2228
private:
	//other methods
	vector<class schClass> section;
};


1
2
3
4
Error	1	error C2027: use of undefined type 'schClass'	
Error	2	error C2228: left of '.year' must have class/struct/union	
Error	3	error C2228: left of '.section' must have class/struct/union
Line 11: remove the keyword class. The compiler already knows from line 5 that schClass is a class.

Line 15: schClass must be fully declared to use as a type in a std::vector. Again, remove the keyword class.

Be sure to include schClass.h before your include of school.h The forward declaration at line 5 should not be needed if your includes are in the proper order.

Since you didn't post schclass.h, can;t tell if line 12 is correct or not.

Thank you for the help but I solved including "schClass.h" in "school.h" (it was in "Include.h")

Anyway I don't know why, I've seen someone else doing that
Topic archived. No new replies allowed.