【发布时间】:2019-11-21 05:13:55
【问题描述】:
class TreeNode {
public:
Box box;
vector<int> points;
vector<TreeNode> children;
};
我有这个简单的节点类。我将节点添加到向量中,然后像这样遍历该向量:
TreeNode root;
vector<TreeNode> activeNodeList;
activeNodeList.push_back(root);
vector<TreeNode>::iterator b = activeNodeList.begin();
while (b != activeNodeList.end()) {
vector<TreeNode> tempNodeList;
// tempNodeList is populated with multiple TreeNode's
(*b.base()).children = tempNodeList;
}
在调试器中,存储在activeNodeList中的节点的children被设置为tempNodeList,但是root的children向量还是空的,这是为什么呢?
【问题讨论】:
标签: c++ vector iterator variable-assignment