Hi all, can you help me figure out why this code doesn't work. The function call to exp() should call the function defined in the complex library. But I have to either give it a complex arg or explicitly convert it to a complex. I would think it would automatically convert to the correct type by matching the arg type.
I tried the C++ Shell and it does not compile. But I'm using GNU GCC. My code compiles under GNU GCC (under Ubuntu, MinGW/MSYS, and Cygwin).
My code does rely on complex_literals (in C++14), but these are recognized by default by the GCC version (except the older version uder Ubuntu, which requires -std=c++14 to compile). Otherwise I did not specify any compiler options.
But even if I explicitly give the command-line options, it still give the same error: it cannot find the function based on the arg list. It recognizes the literals, and it seems to be correctly converting the mixed data-type arg to a complex data type, but it seems to be unable to find the exp() function from the complex library:
1 2 3 4 5 6
g++ -std=c++14 -fext-numeric-literals -Wall test_complex.cpp
test_complex.cpp: In function ‘int main()’:
test_complex.cpp:16:26: error: no matching function for call to ‘exp(__complex__ double)’
z1 = std::exp(1i * PI);
^
I thought I did that already, but I guess I missed it. Thank you!
Addendum: I think I found the source of my error. I found that if I include the namespace complex_literals in my code and give the command line option -fext-numeric-literals, then the compiler issues an error.
1 2 3 4 5 6 7 8
usingnamespace std::complex_literals;
g++ -std=c++14 -fext-numeric-literals test_complex.cpp
test_complex.cpp: In function ‘int main()’:
test_complex.cpp:16:26: error: no matching function for call to ‘exp(__complex__ double)’
z1 = std::exp(1i * PI); //ERROR!