【发布时间】:2021-07-10 05:04:16
【问题描述】:
我正在尝试使用以下方法递归获取节点的所有子节点。 getchildren()、addChildren() 和 Node 的构造函数工作正常,但是当我尝试使用下面的方法获取孩子时,向量 kids 似乎是空的,我不明白为什么在我打印时在方法内部给出n.getX() 和 n.getY() ,它打印值,所以孩子们不应该是空的。这是代码:
void Quad::getChildren(Node n, vector<Node> kids)
{
if(n.getchildren().empty())
{
cout<<"NOOO";
return;
}
else
{
for(Node child: n.getchildren())
{
kids.push_back(child);
getChildren(child, kids);
}
for(Node n: kids)
cout<<n.getX()<<' '<<n.gety()<<endl;
}
}
类似:
vector<Node> kids;
Node n1= Node(0,0,img.cols,img.rows);
Node n2= Node(12,19,34,33);
n1.addChildren(n2);
getChildren(n1,kids);
if(kids.empty())
cout<<"sedfeesdsed";
和输出:
NOOONOOO12 19
sedfeesdsed
目前我只能使用 cout 进行调试
【问题讨论】: