const int ival = 1024;
// still an error
const int *&pi_ref = &ival;If we read this definition from right to left, we discover that pi_ref is a reference to a pointer to an object of type int defined to be const. Our reference isn't to a constant but rather to a nonconstant pointer that addresses a constant object. The correct definition is as follows:const int ival = 1024;
// ok: this is accepted
const int *const &pi_ref = &ival;
请问,为什么一定要constant pointer?
// still an error
const int *&pi_ref = &ival;If we read this definition from right to left, we discover that pi_ref is a reference to a pointer to an object of type int defined to be const. Our reference isn't to a constant but rather to a nonconstant pointer that addresses a constant object. The correct definition is as follows:const int ival = 1024;
// ok: this is accepted
const int *const &pi_ref = &ival;
请问,为什么一定要constant pointer?
解决方案 »
- CDC.TextOut输出的问题?
- 又一个IE抓图的问题,有点难度
- 大家看看这个简单的问题!
- vc中如何调用ASP网页
- 怎样用菜单命令打开一指定路径的文件?
- 为什么我改了菜单中一项的Properties对话框的ID值后,这项就变灰不能用了?(我没选Grayed项)
- 如何在Win32 Dynamic-Link Library创建的DLL中导出多个C++类???解决立即结帐!
- TCP/IP SOCKET编程?
- 关于拨号和判断当前是否在线???
- 为什么dialog.domodal()有时返回-1,重新new project 再将原有的程序拷入,又OK呢?
- 谁帮我稍微解释以下函数
- 控件不能自动下载,什么原因?
核心问题是对指针的引用,核心问题又分为两种比较大的情况:
一、被引用的指针是指针变量
例如:
int ival=1024;
int *pi=&ival;
int *&pi_ref=pi;
pi_ref是一个引用变量,pi_ref改变,pi也随之改变,pi也就不再指向ival了。
二、被引用的指针是指针常量
例如:
int ival=1024;
int * const &pi_ref=&ival;
在程序编译时,ival被分配空间并附值,这时&ival就是一个常量了,pi_就必须是一个引用常量。存储ival的地址无法改变,pi_refint也就无法改变了。int *只不过是修饰指针类型的。
在这种情况下同样还有:
const int ival=1024;
const int * const &pi-ref=&ival;
不知道我说清楚了没有,fangrk(加把油,伙计!)、masterdog(掌门狗)的回帖对我帮助很大,感谢所有的回帖。详见:http://www.csdn.net/expert/topic/812/812983.xml?temp=.5125543