不是“const”的引用;不能绑定到非左值
我对此有点挣扎。
我声明:
BYTE *pImage = NULL;
在调用中使用:
m_pMyInterface->GetImage(i, &imageSize, &pImage);
Visual C++ 2003 编译器错误:
错误 C2664:“CJrvdInterface::GetImage”:无法将参数 3 从“BYTE **__w64”转换为“BYTE **&” ' 不是“const”的引用不能绑定到非左值
调用的方法定义为:
void CMyInterface::GetImage(const int &a_iTileId, ULONG *a_pulImageSize,
BYTE** &a_ppbImage)
非常感谢任何帮助, 伯特
Am struggling a bit with this.
Am declaring:
BYTE *pImage = NULL;
Used in call:
m_pMyInterface->GetImage(i, &imageSize, &pImage);
Visual C++ 2003 compiler error:
error C2664: 'CJrvdInterface::GetImage' : cannot convert parameter 3 from 'BYTE **__w64 ' to 'BYTE **& '
A reference that is not to 'const' cannot be bound to a non-lvalue
The method called is defined as:
void CMyInterface::GetImage(const int &a_iTileId, ULONG *a_pulImageSize,
BYTE** &a_ppbImage)
Any help much appreciated,
Bert
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
因为 GetImage 可以修改它的第三个参数,所以你需要给它一些修改的东西:
有可能在你的函数返回后,
&pImage
和ppImage
可能不再是相同(这也意味着pImage
和*ppImage
可能不同)。如果你添加这个:在通话之后,你应该会很好。
如果
CMyInterface::GetImage
是您自己的函数,则根据您的操作,您也许可以更改它。在你的函数中,你是否曾经这样做:或者你只写:
如果你只做后者而不是前者,那么传递对双指针的引用就太过分了。您可以传递对单指针的引用 (
BYTE *&image
),也可以传递双指针 (BYTE **image
)Because GetImage can modify it's third parameter, you need to give it something to modify:
It is possible that after your function returns, that
&pImage
andppImage
may no longer be the same (which also means thatpImage
and*ppImage
may be different). If you add this:after the call, you should be good.
If
CMyInterface::GetImage
is your own function, depending on what you do, you may be able to change it. In your function, do you ever do:or do you only write:
If you only do that latter and not the former, passing a reference to a double pointer is overkill. You can either pass a reference to a single pointer (
BYTE *&image
) or you can pass a double pointer (BYTE **image
)如果您尝试修改方法“GetImage()”内的变量“pImage”,您应该传递一个指针或对其的引用(不要同时执行两者)。
您可能想要的是:
方法定义为:
PS。放置 & 的位置保持一致。和 * 在类型声明中。
就我个人而言(这只是我的风格,其他人有所不同)我将所有内容都放在左侧(带有类型),只是变量名称放在右侧。
If you are trying to modify the variable 'pImage' inside the method 'GetImage()' you should either be passing a pointer or a reference to it (not doing both).
What you probably want is:
With the method defined as:
PS. Be consistent where you put your & and * in type declarations.
Personally (and this is just my style others are different) I put everything on the left (with the type) just the variable name goes on the right.
您声明 GetImage() 期望引用 Byte**。
您向它传递了对 Byte* 的引用。
为了使您的方法调用按编写的方式工作,您需要将 GetImage() 的定义更改为
You declared GetImage() to expect a reference to a Byte**.
You passed it a reference to a Byte*.
To make your method call work as written, you need to change your definition of GetImage() to