why type casting doesn't work in here?

I know there is some problem with the type casting in here but I don't know what exactly is wrong.

1
2
3
4
5
#define IMG_I (std::complex<double>(0, 1))
#define PI 3.1415926535

for (unsigned long int j = 0; j < 10; ++j)
  std::cout << exp(-IMG_I * PI * j);


This doesn't compile and errors

test00.cpp:13:34: error: no match for ‘operator*’ in ‘std::operator* [with _Tp = double](((const std::complex<double>&)((const std::complex<double>*)(& std::operator- [with _Tp = double](((const std::complex<double>&)((const std::complex<double>*)(& std::complex<double>(0.0, 1.0e+0)))))))), ((const double&)((const double*)(&3.1415926535000000541231202078051865100860595703125e+0)))) * j’


I mean I expect casting from long int to double or std::complex<double> should work fine. But it doesn't!?!

Last edited on
 
std::cout << exp( PI * j * -IMG_I);

Try this :)
Thanks Mercurialol,

But this does not exactly answer my question. I had already solved the problem with putting extra parenthesis,
But what I am looking for is what exactly causes the problem and why the type casting doesn't work in here.
If I know the answer to this then next time I will not spend huge time to find out where the type casting has gone wrong.
Topic archived. No new replies allowed.