interleaving definitions


in A.h i have a class C1 and a type T1 defined with C1.
But A.h needs some definitions in B.h, but in B.h i want to use T1.

Something like:


#include "B.h"
class C1 {
int a; };

typedef set<C1 *> T1;


T1 myC;

but I cant include A.h in B.h. How do I solve my problem?
You probably don't want to define global variables in header files like you do in B.h because if you include the file in more than one translation unit (.cpp file) you will get a linker error saying that myC has been defined multiple times.

If you really want to have global variables you should use an extern declaration in the header
extern T1 myC;
and define it in the source file.
T1 myC;

It doesn't look like myC is used anywhere in A.h so it doesn't need to include B.h.
Last edited on
Topic archived. No new replies allowed.