-
#include woes
It's been a while since I've used C++, and I've gone a little rusty. One problem I managed to overcome in the past was situations where two header files include each other... For example
In resource.h
Code:
#include "resourcemanager.h"
In resourcemanager.h
Code:
#include "resource.h"
... but now I've forgot how to get around it. Can anyone help me out? :)
-
Re: #include woes
There is no easy way around this. One common source of this problem is when two classes need each others declaration. In that case use a forward declaration of one of the classes:
Code:
// b.h
class A;
class B {
A* doSomething();
}
// a.h
#include "b.h"
class A {
B* doSomething();
}
-
Re: #include woes
Thanks! That was the method that I used previously (but had forgot the syntax for!).
-
Re: #include woes
Bah, it turns out to have not worked so well afterall..
Code:
error C2027: use of undefined type 'cResource'
I'm guessing that is related to the forward declaration. The problem is that each class needs to access the members of the other class, and so I don't see any way around it.
Any other ideas? :(
-
Re: #include woes
Put the member accesses into the source files.