What am I doing wrong when I try to execute std::pow(1.0i, 2)
? Is it my understanding of user-defined literal operator""i
, or is it how I use the complex pow
-overload?
The last line shows an error when compiling with g++-6.2 or g++-5:
#include <iostream>
#include <complex>
using std::cout; using std::complex;
int main() {
complex<double> z1 (0, 1);
complex<double> z2 = std::pow(z1, 2);
using namespace std::complex_literals;
complex<double> z3 = std::pow(1.0i, 2); // <<< error
}
The message is:
error: no matching function for call to ‘pow(__complex__ double, int)’
complex<double> z3 = std::pow(1.0i, 2)
If I leave out the last line, all is fine.