Problem with mutiple inclusions and extern declaration

Just wondering is it possible to have two classes include each other where the inclusion guards already put up.

For example


//extern.h
#include "pane1.h"
extern Pane1* pane1;

//some.cc file define this
Pane1 *pane1;

// And in pane1.h i want to use pane1 global variable;
#include "extern.h"
pane1->something();


The compiler says that "error: expected inializer before * of pane1.h"

Just wondering if theres way to work around this.


You can often avoid having include in headers by using forward declarations. In extern.h instead of #include "pane1.h" you write class Pane1; This will work as long as all you have is a pointer (or reference) to that class.
Last edited on
that works thanks, could have saved me 1 hour if I asked early on this forum cheers.

so the new code :

//extern.h
class Pane1;
extern Pane1* pane1;

//some.cc file define this
Pane1 *pane1;

// And in pane1.h i want to use pane1 global variable;
#include "extern.h"
pane1->something();
Topic archived. No new replies allowed.