c++c++11referencecomplex-numbersrvalue

Passing Complex real and imag by reference


The Problem: C++11 has made some changes to complex numbers so that real() and imag() can no longer be used and abused like member variables. I have some code that I am converting over that passes real() and imag() to sincosf() by reference. It looks a little like this:

sincosf(/*...*/, &cplx.real(), &cplx.imag());

This now gives a error: lvalue required as unary '&' operand

which error was not received prior to c++11.

My Question: Is there an easy inline fix? or do I have to create temporary variables to get the result and then pass those to the complex number via setters?

Thanks


Solution

  • Just do

    cplx = std::polar(1.0f, /*...*/);