由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 一个指向指针的指针的引用?
相关主题
问个char*的问题两个继承问题
a simple question for C++ class为什么我看不懂下面的code,是不是水平还不够?
a question about bitwise operationC++疑问
C++菜问: 怎么这样也可以?two c++ interview questions! (转载)
大家来做题C++。请教一个作用域的问题
小白请教一个C++问题:问什么我不能把两个指针=起来?compare double to float
菜鸟求教,一个c++的困惑[合集] C++问题(copy constructor)
请问一个exception题目问一个简单的C++问题
相关话题的讨论汇总
话题: char话题: ptptref话题: pc话题: pprc话题: 指针
进入Programming版参与讨论
1 (共1页)
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);
: ...

1 (共1页)
进入Programming版参与讨论
相关主题
问一个简单的C++问题大家来做题C++。
数组弱问小白请教一个C++问题:问什么我不能把两个指针=起来?
[合集] 关于构造函数菜鸟求教,一个c++的困惑
c++之极弱问请问一个exception题目
问个char*的问题两个继承问题
a simple question for C++ class为什么我看不懂下面的code,是不是水平还不够?
a question about bitwise operationC++疑问
C++菜问: 怎么这样也可以?two c++ interview questions! (转载)
相关话题的讨论汇总
话题: char话题: ptptref话题: pc话题: pprc话题: 指针