K****n 发帖数: 5970 | 1 是不是通过,比如,char**& 来定义?以下代码在vc2008 cl name.cpp /Za编译:
#include
using namespace std;
void PtPtRef(char**& pprc){
(pprc)++;
}
int main(){
char c[] = {'A','B','C','D','E','F','G'};
char* pc=0;
for(int i=0; i
pc = c+i;
cout<<*pc<
PtPtRef(&pc);
cout<<*pc<
}
return 0;
}
得:can not convert parameter 1 from 'char **' to 'char **&'
怎么改呢?
谢谢! |
r****t 发帖数: 10904 | 2 void PtPtRef(char*& pprc);
call it as
PtPtRef(pc); |
K****n 发帖数: 5970 | 3 谢谢,这样确实可以
不过这样不就是“指针的引用”了吗?
题目要求是指针的指针的引用。。。 |
r****t 发帖数: 10904 | 4 your compiler gave confusing info. mine gcc-4.x gives:
error: invalid initialization of non-const reference of type ‘char**&’
from a temporary of type ‘char**’
test.cpp:4: error: in passing argument 1 of ‘void PtPtRef(char**&)’
So, the following should work:
...
ppc = &pc;
PtPtRef(ppc);
...
note your PtPtRef function does ++ppc, probably you want (*ppc)++
instead of ppc++.
【在 K****n 的大作中提到】 : 谢谢,这样确实可以 : 不过这样不就是“指针的引用”了吗? : 题目要求是指针的指针的引用。。。
|
K****n 发帖数: 5970 | 5 哎?我那个括号里是还有一个*的,不知道怎么回事。
好,我回去试试
【在 r****t 的大作中提到】 : your compiler gave confusing info. mine gcc-4.x gives: : error: invalid initialization of non-const reference of type ‘char**&’ : from a temporary of type ‘char**’ : test.cpp:4: error: in passing argument 1 of ‘void PtPtRef(char**&)’ : So, the following should work: : : ... : ppc = &pc; : PtPtRef(ppc); : ...
|