开发者

Vectors inside a struct in C++

struct node {
  char name_;
  vector<node*> nbs_;
};

node a, b, c;
  a.name_ = 'a';
  b.name_ = 'b';
  c.name_ = 'c';
  a.nbs_.push_back(&b);
  a.nbs_.push_back(&c);

  for (vector<node*>::iterator i = a.nbs_.begin(); i != a.nbs_.begin(); i++) {
    cout << (*i)->name_;
  }

Why isn't the above code开发者_如何学运维 working. It prints nothing. I wanted it to print node b's and c's name.


i != a.nbs_.begin();

should be

i != a.nbs_.end();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜