有人写代码是什么意思:
template <class T>
void binaryTree<T>::in_order(Node <T>* node, void (*fun)(T&))
{
if (node == NULL)
return; //<-- what does this mean here
inorder(node->left, fun); //<-- how does this continue here
f(node->data);
inorder(node->right,fun);
}
问题是你如何获得返回;没有返回任何东西。这是做什么的? **注意,为了清楚起见,我已经编辑了上面的代码。
最佳答案
如果你把它格式化得更好,它可能更容易看到:
void foo (int x, int y)
{
if (x == 1)
return;
foo (y);
}
它只是返回如果变量x
等于1
。如果 x
不等于 1
那么代码会跳到对 foo
的递归调用(我真的希望真正的代码不是那样的,因为当它需要两个参数时,你用一个参数调用 foo
。
关于c++ - 返回;只有没有返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19487522/