C++ 通过常量引用传递指针
通过常量引用传递指针不是为了优化吗 前 错误:C++ 通过常量引用传递指针,c++,pointers,reference,constants,C++,Pointers,Reference,Constants,通过常量引用传递指针不是为了优化吗 前 错误: Line 17: Char 28: error: binding reference of type 'const TreeNode *' to value of type 'TreeNode *' not permitted due to incompatible qualifiers testHelper(p, q); ^ Line 12: Char 42:
Line 17: Char 28: error: binding reference of type 'const TreeNode *' to value of type 'TreeNode *' not permitted due to incompatible qualifiers
testHelper(p, q);
^
Line 12: Char 42: note: passing argument to parameter 'p' here
bool testHelper(const TreeNode*& p, const TreeNode*& q) {
^
通过常量引用传递指针不是为了优化吗
不,它不是,因为它没有更快。添加的间接寻址可能较慢
这些不是对const的引用。这些是对指向常量的非常量指针的引用
其他错误:
已声明为返回非void,但缺少返回语句test
- 您尚未声明调用的函数
recursiveHelper
其他错误:
已声明为返回非void,但缺少返回语句test
- 您尚未声明调用的函数
recursiveHelper
booltesthelper(const-TreeNode*const&p,const-TreeNode*const&q)
将通过const
引用传递它。第一个问题:为什么首先是指针?第二个问题:通过像指针一样传递一个微不足道的复制值作为引用,您会得到什么?booltesthelper(const TreeNode*const&p,const TreeNode*const&q)
将通过const
引用传递它。
Line 17: Char 28: error: binding reference of type 'const TreeNode *' to value of type 'TreeNode *' not permitted due to incompatible qualifiers
testHelper(p, q);
^
Line 12: Char 42: note: passing argument to parameter 'p' here
bool testHelper(const TreeNode*& p, const TreeNode*& q) {
^
bool testHelper(const TreeNode*& p, const TreeNode*& q)