Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

warning C4238: nonstandard extension used : class rvalue used as lvalue

Here my code

   if(bSelected)
{
    clrTextSave=pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
    clrBkSave=pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
    pDC->FillRect(rcAllLabels,&CBrush(::GetSysColor(COLOR_HIGHLIGHT)));
}
else
    pDC->FillRect(rcAllLabels,&CBrush(m_clrTextBk));

When I complie on Visual studio 2008 it give me : warning C4238: nonstandard extension used : class rvalue used as lvalue I don't know how to fix this warning? Plz somebody help? Thank you !

like image 598
TrungLuu Avatar asked Aug 22 '13 03:08

TrungLuu


1 Answers

You are getting the warning (which should be an error because you should always compile your code using the highest warning level) because you are creating a temporary and using it's address. To prevent this warning, you need to create a local variable instead:

if(bSelected)
{
    clrTextSave = pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
    clrBkSave = pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
    CBrush brush(::GetSysColor(COLOR_HIGHLIGHT)); // create a local variable
    pDC->FillRect(rcAllLabels, &brush); // use its address
}
else
{
    CBrush brush(m_clrTextBk); // same thing here
    pDC->FillRect(rcAllLabels, &brush);
}
like image 153
Zac Howland Avatar answered Nov 13 '22 08:11

Zac Howland