You need to use forward announcements to work your solution. The easiest way is to put these classes in the same header file (but it can be solved somewhat differently):
class StorageHistory; // *** Forward declaration *** class Storage { public: Int m_cnt; <lots of other members...> StorageHistory m_his; }; class StorageHistory { public: std::vector<Storage> m_history_vec; };
I do not like your decision. M_his will contain a list of storage classes, and all of them will contain a list of storage classes (albeit empty).
I would create a singleton with a storage vector map and wrap the storage with a container containing a UID.
class StorageContainer { private: static int nextUID = 0; int uid; Storage data; public: StorageContainer() { uid = nextUID++;
Then you can access the repository history by its UID.
class StorageHistory { // The usual singleton stuff private: std::unordered_map<int, std::vector<Storage>> history; public: std::vector<Storage> & operator[] (int uid) { auto iter = history.find(uid); if (iter == unordered_map::end) { std::vector<Storage> newHistory; history[uid] = newHistory; } return history[uid]; } };
source share