解決しようとしている次の循環依存関係の問題があります。
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;
};
my_class が typedef の前に宣言されていないため、コンパイラはこれを好みません。
次のように myclass を前方宣言しようとすると:
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;
};
「エラー: 'my_class' の前方宣言」が表示されます。
どうすればこの悪循環を断ち切ることができるでしょうか?
申し訳ありませんが、私の表現が少し間違っていることに気付いたので、質問を修正する必要があります。
以下は私の問題の正しい表現です:
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;
};
これにつきましては申し訳ございません