Breaking cyclic dependency in C++ -
I have the following cyclic dependency problem I am trying to solve:
Typedef std:: map & lt; Int, my_class & gt; My_map; Class my_class {... private: my_map :: iterator iter; }; Class other classes {public: my_map :: iterator getIter (); Private: my_map map; };
The compiler does not like it, because my_class was not declared before typedef.
If I try to forward myclass like this:
class my_class; Typedef std :: map & lt; Int, my_class & gt; My_map; Class my_class {... private: my_map :: iterator iter; }; Class other classes {public: my_map :: iterator getIter (); Private: my_map map; };
I get an error: the forward declaration of 'my_class'. "
How can I break this vicious cycle?
I am sorry, but I have to amend my question, because I have seen that my representation is a bit wrong.
The following is a true representation of my problem:
class my_container; Typedef std :: map & lt; int, my_container & gt; my_map; class my_class {... Private: my_map :: iterator iter;} class my_container {public: my_class a_method (private): vector v;}; class other class {public: my_map :: iterator a_method (); My_class another_method (); My_container is still_one_math (); private: my_map map;};
Sorry about
class my_class; typedef std :: map & lt; int, my_class * & gt; my_map; ~~~~~~~~~~ use the pointer here!
Comments
Post a Comment