samedi 21 avril 2018

C++ Complex library compile error

Here is my code:

#include <iostream>
#include <iomanip>
#include <complex>
#include <cmath>

int main()
{

using namespace std::complex_literals;

std::cout<< std::fixed<<std::setprecision(1);

std::complex<double> z1= 1i *1i;   //imaginary unit squared
std::cout<<"i * i= " <<z1 <<'\n';

std::complex<double> z2=std::pow(1i, 2); //imaginary unit squared
std::cout <<"pow(i,2) =" <<z2 <<'\n';


}

I compile with gcc hello.cpp -lstdc++ -o hello.o

Basically it won't let me double the powers of a complex number when i do std::complex z2=std::pow(1i, 2);..

I get the following error

error: no matching function for call to 'pow(complex int, int)' std::complex z2=std::pow(1i, 2);

However, if i remove the complex number and do std::complex z2=std::pow(2, 2);

it returns 4, the correct answer..

There are many more lines of compile errors, but i made it brief

Aucun commentaire:

Enregistrer un commentaire