这是有问题的代码!我没有花太多时间在C ++上,并且正在实现二进制搜索树。
void BST::Preorder(void(*visit)(const Node *))
稍后,该函数的调用方式如下:
bst.Preorder(PrintNode)
使用PrintNode实现如下:
void PrintNode(const Node* n)
{
cout << n->GetValue() << ",";
}
被要求实现此Preorder函数-但是我对这里发生的事情感到非常困惑。谁能指出我的正确方向。谢谢。
Preorder
function ofBST
class.*visit
means it's a function pointer that accept aconst Node *
as its own paremeter and return void.So generally you would have to implement that
visit
function elsewhere. Then uses thatvisit
function somewhere inPreorder
function.This is a parameter of type pointer to function accepting
const Node *
and returnsvoid
and the name of the parameter isvisit
.In other words if you have a function like
func()
, you can pass it toBST::Preorder()