尝试将我的二叉搜索树(BST) 的根传递给UI 函数(我需要将其作为可修改变量传递或以其他方式传递)
main.cpp
cmd = UI.uiCmd()
BST<Matrix> *data = new BST<Matrix>;
Matrix mat;
UI.handle (cmd, mat, data); // passing command, class object, root of BST
header 中的 UI 类有:
private:
void handle (int, Matrix, BST<Matrix *>);
在 .cpp 文件中:
void ui::handle(int cmd, Matrix matrix, BST<Matrix *> data)
我知道我在某个地方搞砸了,但我不能说在哪里,我对指针的把握很差
我得到的错误:它认为 BST<Matrix>&*
while 函数询问 BST<Matrix> *
我目前不打算大量使用 C++,因此不需要详细的回答(虽然不胜感激)。
最佳答案
你的函数签名应该是这样的
void handle (int, Matrix, BST<Matrix>*)
代替
void handle (int, Matrix, BST<Matrix *>)
关于c++ - 再次将指针传递给函数时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11032082/