I have these two classes:
include/state.hpp :
#include "connection.hpp"
#include <vector>
class state {
private:
vector<connection*> conns;
...
};
include/connection.hpp :
#include "state.hpp"
class connection {
private:
state *next;
...
};
And my src/main.cpp :
#include "../include/state.hpp"
#include "../include/connection.hpp"
int main(...) {
...
}
The problem is that when I compile I get a lot of errors because the compiler doesnt know what is "state" or "connection" when it needs them. I found a solution doing this:
include/state.hpp :
#include "connection.hpp"
#include <vector>
class connection;
class state {
private:
vector<connection*> conns;
...
};
include/connection.hpp :
#include "state.hpp"
class state;
class connection {
private:
state *next;
...
};
Anyway, this is all but clean in my opinion. Should I create other .hpp file with all the classes and include them in the rest of the .hpp like this ? :
include/classes.hpp :
class state;
class connection;
class foo;
...
Is there a better solution ?