Harsha
Harsha

Reputation: 20

C++ : lvalue required as unary ‘&’ operand

The following Piece of code worked in my work system, the same code is throwing an error in my PC.

std::bitset<32> my_bit(*(uint32_t*)&(OFDM_cod[V][a/8].real()));

Error:
lvalue required as unary ‘&’ operand

Any suggestions why is this happening? Thanks in Advance!

Upvotes: 0

Views: 762

Answers (1)

SergeyA
SergeyA

Reputation: 62603

You can't take an address of the temporary, and this is what

&(OFDM_cod[V][a/8].real()));

is doing. It can be simplified to

&x.real(); //here assuming real() does not return a reference

and this is not good. Your code probably works in a non-standard compliant compiler, which is relaxed about this stuff - but this behavior is against the C++ standard.

Upvotes: 4

Related Questions