I am developing an application in C++. In this app, I have two classes: database class and user class. Database class contains a list of pointers to users. In this class, I need to access to user's pointer to save information about users in an external file. In user class, I have all user's information.
Now, I would like to access to the database from user class, because I need scan it. My problem is this: Database class include user's class and when I include database from user's class I get a circular dependency. What can I do?
Forward declaration doesn't help me, cause I need to use methods both from user and from database.
Here a code example:
#include "user.h"
class Database{
private:
std::map<string,User*> userList;
public:
....
methods to use database
....
};
#include "database.h" // if I add this I get cirular-dep
class User{
private:
...user informations..
public:
...
I need a method here to access to db
...
};