Problem compiling multiple header files

Hello all, I am having a problem compiling my project, here's the rundown of what's going on.

I have two classes, for simplicity let's call them Class A and Class B.

In Class A I have a list (linked list, used #include<list>) of B objects.
In Class B I have a list (linked list) of A objects.

In each Class header I have the proper include statements, using namespace std, etc etc, I also include the other class as well, i.e. #include "classB", and so forth.

However when I compile, it'll tell me that it cannot find the specified Type B at all in the Type A header file. When I comment this line out all else works, I do not know what is causing this error.

Any ideas?

edit:

Also, I have made classes before and I included all the necessary elements like #ifndef, etc. Like I said, the classes compile perfectly when I comment out the one line.
Last edited on
Sounds like a circular include. If a.h is including b.h, then b.h cannot include a.h.

See section 4 on this page:

http://www.cplusplus.com/forum/articles/10627/#msg49679
Ah okay I see, so basically to foward declare a class you do

class B;
class A
{}

and in class A you can use a pointer to B

I compiled with these modifications and it worked, this is the right way to do it, correct?
yup.
Topic archived. No new replies allowed.