Reputation: 1484
Is passing a pointer by const reference not done for optimization?
Ex.
bool testHelper(const TreeNode*& p, const TreeNode*& q) {
return false;
}
TreeNode* test(TreeNode* root, TreeNode* p, TreeNode* q) {
recursiveHelper(p, q);
}
Error:
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) {
^
Upvotes: 0
Views: 167
Reputation: 238491
Is passing a pointer by const reference not done for optimization?
No, it isn't, because it isn't any faster. The added indirection is potentially slower.
bool testHelper(const TreeNode*& p, const TreeNode*& q)
Those are not references to const. Those are references to non-const pointers to const.
Other bugs:
test
was declared to return non-void but lacks a return statementrecursiveHelper
that you call.Upvotes: 2