1

这是 .h 文件中的一项功能

LinkedListElement<char> * findLastNthElementRecursive(int n, int &current);

尝试两者

findLastNthElementRecursive(3,0);

int a = 0;
findLastNthElementRecursive(3,&a);

错误是没有匹配的功能

我知道findLastNthElementRecursive(3,a);应该这样

但是如果我不想创建像 a 这样的新变量,该怎么做?

4

2 回答 2

3

临时不能绑定到非const引用。在您的第一种情况下,您尝试将临时文件作为参数传递,但它失败了。

第二个不起作用,因为&a它的地址a实际上是一个int*,因此与函数的签名不匹配。

正确的方法是

int a = 0;
findLastNthElementRecursive(3,a);
于 2012-12-06T18:30:48.053 回答
1

尝试:

int a = 0;
findLastNthElementRecursive(3, a);

另请注意,您忽略了findLastNthElementRecursive().

于 2012-12-06T18:30:36.403 回答