Main.cpp
#include "Test1.h"
#include "Test2.h"
int main(){
Test1 t1;
Test2 t2;
t1.process(t2);
t2.process(t1);
}
Test1.h
#ifndef TEST1
#define TEST1
#include "Test2.h"
class Test1 {
public:
void process(const Test2& t) {};
};
#endif // !TEST1
Test2.h
#ifndef TEST2
#define TEST2
#include "Test1.h"
class Test2 {
public:
void process(const Test1& t) {};
};
#endif // !TEST2
VS2012 says:
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2143: syntax error : missing ',' before '&'
error C2664: 'Test2::process' : cannot convert parameter 1 from 'Test1' to 'const int'
I am pretty sure it's the circular includes problem again (I come across it once in a while), but this time I am not sure why doesn't this compile.
Notice: the classes only depend on each other's references, which are of known size. Is it because of the include guards (#ifndef
), that make one of the Test headers include the other as an empty file?