【发布时间】:2018-05-12 10:45:37
【问题描述】:
这可能是一个愚蠢的问题,但由于我是编程新手,尤其是 c++,我想我会在这里问。我在一个类中有以下方法:
/*! Copies the image data from an external raw buffer to
* the internal image buffer.
*
* The member function ASSUMES that the input buffer is of a size compatible
* with the internal storage of the Image object and that the data buffer has
* been already allocated. If the image buffer is not allocated or the
* width or height of the image are 0, the method should exit immediately.
*
* \param data_ptr is the reference to the preallocated buffer from where to
* copy the data to the Image object.
*/
void setData(const Color * & data_ptr);
* & 有什么特别的含义吗?我知道 Color* 显然是一个指针,但我遇到了麻烦。代码的cmets中提到的外部原始缓冲区是一个浮点数组,内部图像缓冲区是一个Color*缓冲区(Color是同一命名空间内的另一个类)。
编辑:哇,感谢所有反对票!它不像我提到的我是初学者,现在才开始接触这门语言。必须爱上 stackoverflow 社区。你让学习变得如此有趣!
【问题讨论】:
-
&表示引用。const Color * & data_ptr表示data_ptr是对const Color *的引用。见stackoverflow.com/questions/373419/… -
Color*是一个指针,类型定义中的&表示它是对指定类型的引用。因此 - 它是对指向Color的指针的引用。请阅读good C++ book。