尝试将我的二进制搜索树(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头中的UI类有:
private:
void handle (int, Matrix, BST<Matrix *>);在.cpp文件中:
void ui::handle(int cmd, Matrix matrix, BST<Matrix *> data)我知道我在哪里搞砸了,但我说不出是哪里,我对指针掌握得很差
我得到的错误:,它认为是BST<Matrix>&*,而函数问BST<Matrix> *
我目前不打算多使用C++,所以没有必要给出详细的答案(虽然很感激)。
发布于 2012-06-14 11:30:47
您的函数签名应该看起来像
void handle (int, Matrix, BST<Matrix>*)而不是
void handle (int, Matrix, BST<Matrix *>)发布于 2012-06-14 11:31:31
首先,BST<Matrix *>与BST<Matrix>*不一样。一个是指针容器,另一个是指向容器的指针。
其次,如果要让函数修改一个参数,可以通过引用传递它:
void ui::handle(int cmd, sMat matrix, BST<sMat>& data) 把它叫做
cmd = UI.uiCmd()
BST<Matrix> data;
Matrix mat;
UI.handle(cmd, mat, data);发布于 2012-06-14 11:31:04
你创造了
BST<Matrix> *data = new BST<Matrix>;但是函数请求一个BST<Matrix*>参数。注意细微的差别
BST<Matrix> * IS NOT same as BST<Matrix*>https://stackoverflow.com/questions/11032082
复制相似问题