<分区>
Possible Duplicate:
What is the difference between const int*, const int * const, and int const *?
我想了解 const
在函数参数中的工作原理。 void function(int const *&i);
和 void function(const int *&i);
有什么区别?如果您能举例说明它们的实现和 i
的用法,我将不胜感激。
<分区>
Possible Duplicate:
What is the difference between const int*, const int * const, and int const *?
我想了解 const
在函数参数中的工作原理。 void function(int const *&i);
和 void function(const int *&i);
有什么区别?如果您能举例说明它们的实现和 i
的用法,我将不胜感激。
最佳答案
它们是一样的,从右往左读就可以了:
First example: i is a reference to a pointer of a constant integer.
Second example: i is a reference to a pointer of an integer constant.
const 的放置只会改变指针两边的内容。例如:
const int* i
意思是:i是一个指向常量整数的指针
而 int* const i
表示:i是一个指向整数的常量指针。
关于函数声明中的 C++ const 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5861497/