Sumith Yesudasan
Sumith Yesudasan

Reputation: 51

issues with complex number in VS 2010

#include <complex>
using namespace std;

mx_vector = new double [NX]; //NX = 200
imx_vector = new complex<double> [NX];

i = 1;
imx_vector[i].real () = 0.0;
imx_vector[i].imag () = mx_vector[i]; //mx_vector[i] = 2.2

//This is part of a big program, so hiding the simple details like main() etc.

Hi, I have this code and was working well with intel c++ in redhat linux. Now when I compile it in VS 2010 I get the error "error C2106: '=' : left operand must be l-value". I have looked up the MSDN ref, previous posts on stackflow but couldnt fix it. Is there something to do with "new"?

Any help/reference will be highly appreciated.

Upvotes: 1

Views: 200

Answers (1)

Piotr Skotnicki
Piotr Skotnicki

Reputation: 48447

imx_vector[i].real() as well as imx_vector[i].imag() return the double, not double&.

You probably meant (C++98):

imx_vector[i] = std::complex<double>(0.0, mx_vector[i]);

or (C++11):

imx_vector[i].real(0.0);
imx_vector[i].imag(mx_vector[i]);

Upvotes: 5

Related Questions