I have the following cyclic dependency problem I am trying to solve:
typedef std::map<int, my_class> my_map;
class my_class {
...
private:
my_map::iterator iter;
};
class otherclass{
public:
my_map::iterator getIter();
private:
my_map map;
};
The compiler does not like this, since my_class was not declared before the typedef.
if I try to forward-declare myclass like this:
class my_class;
typedef std::map<int, my_class> my_map;
class my_class {
...
private:
my_map::iterator iter;
};
class otherclass{
public:
my_map::iterator getIter();
private:
my_map map;
};
I get an "error: forward declaration of 'my_class'".
How can I break this vicious cycle?
I'm sorry but I have to revise my question, as I have noticed that my representation is slightly wrong.
The following is the correct representation of my problem:
class my_container;
typedef std::map<int, my_container> my_map;
class my_class {
...
private:
my_map::iterator iter;
};
class my_container {
public:
my_class a_method();
private:
vector<my_class> v;
};
class otherclass{
public:
my_map::iterator a_method();
my_class another_method();
my_container yet_another_method();
private:
my_map map;
};
Sorry about this