cross reference problem

I cant get the following code compiled. The following code is an abstraction of the problem I met in my development. How do you usually solve this kind of problem in your project?

test1.h
1
2
3
4
5
6
7
8
9
10
11
12
13
#ifndef TEST1_H
#define TEST1_H

#include "test2.h"

class Test2;

class Test1 {
public:
	typedef struct Nested {} N;
};

#endif 


test2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
#ifndef TEST2_H
#define TEST2_H

#include "test1.h"

class Test1;

class Test2 {
public:
	Test1::N m;
};

#endif 


test.cpp
1
2
3
4
5
6
#include "test1.h"

int main()
{
	Test1 t1;
}
Last edited on
4) The "right way" to include http://www.cplusplus.com/forum/articles/10627/
Files cannot inlucde each other. In test1.h it is completely unnecessary to include test2.h. Not even the forward reference is required.

Either include or forward reference, but not both.
Topic archived. No new replies allowed.