gaugi
gaugi

Reputation: 103

C++11x and Eigen library

I want to compile a program, where I initialize a complex matrix MatrixXcd in Eigen using

MatrixXcd M;
M.resize(length,length);

M(i,j).real()=f(i,j)
M(i,j).imag()=f(i,j)

where f(i,j) is some function of type std::complex<double> of i,j. It all works fine, unless I use the -std=c++0x compiler option, which I do need. When using this option, I get the error:

error: lvalue required as left operand of assignment

For the above line of code, what is going wrong?

Upvotes: 0

Views: 377

Answers (1)

Kerrek SB
Kerrek SB

Reputation: 477110

Change it to:

M(i, j) = f(i, j);

That's already assigning the real part only.

If you want to assign a general complex number given its real and imaginary parts, use e.g.

M(i, j) = std::complex<double>(f(i, j), g(i, j));

Upvotes: 1

Related Questions