- #1
sam2
- 22
- 0
Hi,
Has anyone here used the complex C++ class before Header <complex>? I am trying to do something VERY straightforward but there doesn't seem to be any way to do it!
Basically, I define a complex, and then want to re-asign its real and imaginary parts:
complex<double> A(1,1); // assign real and I am parts to 1.
//Now I want to change the real and imaginary parts to 2, 2
A.real() = 2; //error
//The only way I can make it work is
A = complex<double> (2,2);
//but I am guessing that this is much less efficient because you are basically recalling the complex constructor followed by the assignment operator!
Does anyone know how to do this? It seems silly that you can not access the real and imaginary parts of the class via a function of the form
double& complex<double>::real();
Thanks,
Has anyone here used the complex C++ class before Header <complex>? I am trying to do something VERY straightforward but there doesn't seem to be any way to do it!
Basically, I define a complex, and then want to re-asign its real and imaginary parts:
complex<double> A(1,1); // assign real and I am parts to 1.
//Now I want to change the real and imaginary parts to 2, 2
A.real() = 2; //error
//The only way I can make it work is
A = complex<double> (2,2);
//but I am guessing that this is much less efficient because you are basically recalling the complex constructor followed by the assignment operator!
Does anyone know how to do this? It seems silly that you can not access the real and imaginary parts of the class via a function of the form
double& complex<double>::real();
Thanks,