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();
精彩评论