Non-const reference cannot be bound to non-lvalue

I'm struggling a bit with this.

Declare:

BYTE *pImage = NULL;

Used when calling:

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 link not related to' const 'cannot be bound to non-lvalue

The called method is defined as:

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

Any help is much appreciated, Bert

+3
source share
3 answers

Since GetImage can change the third parameter, you need to give it something to change:

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

, , &pImage ppImage ( , pImage *ppImage ). :

if (ppImage)
    pImage = *ppImage;

, .

CMyInterface::GetImage - , , , . - :

a_ppbImage = ...;

:

*a_ppbImage = ...;

, , . (BYTE *&image), (BYTE **image)

+8

"pImage" "GetImage()", , ( ).

, , :

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)

( , ). ( ), .

0

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

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

You gave him a link to the byte *.

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

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

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

Source: https://habr.com/ru/post/1742519/


All Articles