不是“const”的引用;不能绑定到非左值

发布于 2024-08-29 21:08:38 字数 544 浏览 5 评论 0原文

我对此有点挣扎。

我声明:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧城空念 2024-09-05 21:08:38

因为 GetImage 可以修改它的第三个参数,所以你需要给它一些修改的东西:

BYTE **ppImage = &pImage;
m_pMyInterface->GetImage(i, &imageSize, ppImage);

有可能在你的函数返回后,&pImageppImage可能不再是相同(这也意味着 pImage*ppImage 可能不同)。如果你添加这个:

if (ppImage)
    pImage = *ppImage;

在通话之后,你应该会很好。

如果 CMyInterface::GetImage 是您自己的函数,则根据您的操作,您也许可以更改它。在你的函数中,你是否曾经这样做:

a_ppbImage = ...;

或者你只写:

*a_ppbImage = ...;

如果你只做后者而不是前者,那么传递对双指针的引用就太过分了。您可以传递对单指针的引用 (BYTE *&image),也可以传递双指针 (BYTE **image)

Because GetImage can modify it's third parameter, you need to give it something to modify:

BYTE **ppImage = &pImage;
m_pMyInterface->GetImage(i, &imageSize, ppImage);

It is possible that after your function returns, that &pImage and ppImage may no longer be the same (which also means that pImage and *ppImage may be different). If you add this:

if (ppImage)
    pImage = *ppImage;

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:

a_ppbImage = ...;

or do you only write:

*a_ppbImage = ...;

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)

清泪尽 2024-09-05 21:08:38

如果您尝试修改方法“GetImage()”内的变量“pImage”,您应该传递一个指针或对其的引用(不要同时执行两者)。

您可能想要的是:

BYTE *pImage = NULL;
x.GetImage(iTileId, pulImageSize, a_pImage );

方法定义为:

void CMyInterface::GetImage(int const& a_iTileId, ULONG* a_pulImageSize, BYTE*& a_ppbImage)
{
}

PS。放置 & 的位置保持一致。和 * 在类型声明中。

ULONG   *a_pulImageSize   // Star on the right
BYTE**   &a_ppbImage      // Star on the left (not consistent)

就我个人而言(这只是我的风格,其他人有所不同)我将所有内容都放在左侧(带有类型),只是变量名称放在右侧。

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:

BYTE *pImage = NULL;
x.GetImage(iTileId, pulImageSize, a_pImage );

With the method defined as:

void CMyInterface::GetImage(int const& a_iTileId, ULONG* a_pulImageSize, BYTE*& a_ppbImage)
{
}

PS. Be consistent where you put your & and * in type declarations.

ULONG   *a_pulImageSize   // Star on the right
BYTE**   &a_ppbImage      // Star on the left (not consistent)

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.

春庭雪 2024-09-05 21:08:38

您声明 GetImage() 期望引用 Byte**。

void CMyInterface::GetImage(const int &a_iTileId, 
                            ULONG *a_pulImageSize,
                            BYTE** &a_ppbImage);

您向它传递了对 Byte* 的引用。

BYTE *pImage = NULL;
m_pMyInterface->GetImage(i, &imageSize, &pImage);

为了使您的方法调用按编写的方式工作,您需要将 GetImage() 的定义更改为

void CMyInterface::GetImage(const int &a_iTileId, ULONG *a_pulImageSize,  
                            BYTE* &a_ppbImage) 

You declared GetImage() to expect a reference to a Byte**.

void CMyInterface::GetImage(const int &a_iTileId, 
                            ULONG *a_pulImageSize,
                            BYTE** &a_ppbImage);

You passed it a reference to a Byte*.

BYTE *pImage = NULL;
m_pMyInterface->GetImage(i, &imageSize, &pImage);

To make your method call work as written, you need to change your definition of GetImage() to

void CMyInterface::GetImage(const int &a_iTileId, ULONG *a_pulImageSize,  
                            BYTE* &a_ppbImage) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文