|
-
Jan 6th, 2006, 10:02 AM
#1
Thread Starter
Addicted Member
#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?
Using Visual Studio .NET 2005
-
Jan 6th, 2006, 12:58 PM
#2
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();
}
-
Jan 8th, 2006, 10:33 AM
#3
Thread Starter
Addicted Member
Re: #include woes
Thanks! That was the method that I used previously (but had forgot the syntax for!).
Using Visual Studio .NET 2005
-
Jan 9th, 2006, 05:53 AM
#4
Thread Starter
Addicted Member
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?
Using Visual Studio .NET 2005
-
Jan 9th, 2006, 06:34 AM
#5
Re: #include woes
Put the member accesses into the source files.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|