Archived

This topic is now archived and is closed to further replies.

Blackstream

C++ Class help, please

Recommended Posts

Okay, its like this. I have two classes (EDDrawMain, and EDDrawSurface) I''m using to wrap DirectX. EDDrawMain uses EDDrawSurface as its data memembers for the primary surface and the backbuffer. EDDrawSurface uses EDDrawMain in order to initialize itself. See my problem yet? When I try to make the two header files include each other, my compiler looks at EDDrawMain.h and says that EDDrawSurface isn''t a valid identifier... even though it includes the class header file. Basically, I need to know how to have Class A include B AND Class B include A. I hope there is a way. -Blackstream -Blackstream "See you later, I'm going to go grab a few Bytes. I'm so thirsty, I could drink a whole data stream."

Share this post


Link to post
Share on other sites
Not sure if this is what you mean, but to get 2 classes to include each other, you must ''declare'' one (or both) of the classes before the classes themselves. eg


class classA; // these lines declare that the classes exist
class classB; // and will be implemented somewhere later in code

class classA
{
public:
classB *classBInstance;
}

class classB
{
public:
classA *classAInstance;
}

This is similar to when you declare functions in a header file and define them later.

Cel

Share this post


Link to post
Share on other sites
Can you remove EDDrawMain.h from the header file for EDDrawSurface?

Put EDDrawMain.h in the EDDrawSurface.cpp file.

Also, in your EDDrawMain.h, remove the
    
#include EDDrawSurface

and replace with


class EDDrawSurface;

Share this post


Link to post
Share on other sites
Okay, thanks, I''ll try that. I was hoping I wouldn''t have to stuff them all into the same header, but it is better than making the classes a little illogical so that only Class A needs Class B by moving part of B to A. I actually tried the

class ClassA;

thing, but then again, I think my problem was not that they weren''t defined, but since my files could only be included once, ClassA got B, but B didn''t get A. Does that make sense?


--------------------------------------------------------------
-Blackstream

Don''t you dare run with sharp uninitialized addresses pointing to who knows where! You could trip, and Poke() something out!

-What the Motherboard says to her kids

Share this post


Link to post
Share on other sites