So my typedef
is like:
typedef struct {
B b;
std::list<A>::iterator iter;
} A;
I know a self-referential pointer works, but not so sure about an iterator, although they are quite alike. Just want to make sure, thanks.
答案 0 :(得分:0)
typedef struct { /*...*/ } A;
是残留的C语法。 C ++的写法是
struct A { /* ... */ };
至于存储迭代器,不清楚为什么你对此有任何困惑。
但是,使用迭代器需要谨慎。许多操作可能使现有运算符无效,例如:
std::vector<int> v;
v.push_back(1);
v.push_back(2);
std::vector<int>::iterator it = v.begin() + 1; // references 2
v.insert(v.begin() + 1, 0); // invalidates it
存储迭代器是引领这种伤害世界的必然方法。