c++ - 再次将指针传递给函数时遇到问题

标签 c++ pointers parameter-passing

尝试将我的二叉搜索树(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/

相关文章:

c++ - 实现加权图的问题[c++]

c++ - 反转字符串函数 C++

c - 为什么我必须返回指针?

C - 指针 - 我理解得好吗?

c++ - 通过常量值传递 vector 与通过常量引用传递 vector

c# - 传递 ValueTuple 而不是参数

parameter-passing - 带有 json 对象参数的 javascript 函数

c++ - 在类中操作 vector 的成员

c++ - 将 jpeg 放入 MySQL 表所需的准系统 C++ 代码是什么?

c - 为什么我不需要 scanf 的符号? (在 C 中)