PDA

View Full Version : c2102 & requires L-value after usage with casting operator



FriedrichIWM
27th October 2011, 13:16
Hi guys,

can anybody tell me why



shmlayer_dataptr_t *ProcessImagePtr;
ProcessImagePtr = &(shmlayer_dataptr_t)ProcessImage;


is crashing in qt4.7.4 (qmake) with C2102 (but is it working with visual studio compiler for example) while



shmlayer_dataptr_t temp;
shmlayer_dataptr_t *ProcessImagePtr;
temp = (shmlayer_dataptr_t)ProcessImage;
ProcessImagePtr = &temp;


is working???

Thanks a lot!



shmlayer_dataptr_t *ProcessImagePtr;
ProcessImagePtr = &((shmlayer_dataptr_t&)ProcessImage);

is working with qt but not with visual studio c compiler

d_stranz
27th October 2011, 17:51
So what makes this a Qt question? Even if it was a Qt question (and not one of basic C++ syntax and usage), you haven't shown us enough code to answer the question. (Like what is "ProcessImage" for example?)

amleto
29th October 2011, 13:01
Firstly, if you get a compiler error, it IS NOT a crash.

Secondly, do you know the difference between lvalue and rvalue? Your working example should show you...

The compiler error states it needs an lvalue. casting like that gives an rvalue.


You should be casting pointers anyway, not instances.