-
problem with compiling
Hello..
I have 2 headers.
The first one is:
Code:
#ifndef SESSION_HEADER
#define SESSION_HEADER
#include "header2.h"
class session {
public:
session() { }
thread *threads;
thread *get_thread(unsigned short id);
..etc..
};
#endif
And the other one is:
Code:
#ifndef THREAD_HEADER
#define THREAD_HEADER
#include "header1.h"
class thread {
public:
thread(session *se) { s = se; }
session *s;
thread *next;
};
#endif
Now im getting errors when compiling, I think because the compiler wants to include header which would need the first header.. I know for extern, but is this the way how should I do it? And if I should, how would be the right way to do it?
Thanks for help guys
-
You are using only pointers to the other class, so a forward declaration should do.
e.g.
Code:
#ifndef SESSION_HEADER
#define SESSION_HEADER
// #include "header2.h" // not needed
class thread;
class session {
public:
session() { }
thread *threads;
thread *get_thread(unsigned short id);
..etc..
};
#endif
Kurt
-
One possibility is to remove #include "header2.h" and replace it with a forward declaration of the thread class.
Code:
class thread;
class session {
public:
session() { }
thread *threads;
thread *get_thread(unsigned short id);
..etc..
};
-