什么是*& mean in:void setData(const Color *& data_ptr);

时间:2017-11-28 20:49:52

标签: c++ methods colors ppm

这可能是一个愚蠢的问题,但由于我是编程新手,尤其是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 *显然是一个指针但是我遇到了麻烦。代码注释中提到的外部原始缓冲区是一个float数组,内部图像缓冲区是一个Color *缓冲区(Color是同一名称空间内的另一个类)。

编辑:哇谢谢所有的投票!它不像我在初学者级别提到我刚刚开始进入语言。喜欢stackoverflow社区。你让学习变得如此有趣!

1 个答案:

答案 0 :(得分:4)

从右到左阅读:对指向Color的指针的引用。

也就是说,您通过引用传递指针,以便函数可以更改它。 const适用于Color,而不适用于指针或引用。我更喜欢与Color const* & data_ptr编写相同的内容,以便您可以从右向左阅读并查看const适用的内容。