I have two classes named Manager
and Worker
. Each Worker
has a Manager
and each Manager
has a Worker
to manage.
I am defining the classes at separately header files.
manager.h
#include "worker.h"
class Manager{
private:
Worker* worker;
public:
/* methods etc */
};
worker.h
#include "manager.h"
class Worker{
private:
Manager* manager;
public:
/* methods etc */
};
main.cpp
#include "worker.h"
#include "manager.h"
int main(void){
/* code code */
}
Ok until now it seems to be everything ok, but when I try to compile it gives lots of lines with the names of the headers.
First I thought that it created a kind of loop and was including the headers endless. I then searched about it and tried to use #ifndef #define #endif
in each header file. Turns out that now the problem is that the class Worker doesn't see the class Manager and vice-versa, meaning that the errors now are "'Worker' does not name a type" etc etc etc.