There are different ways to represent complex number in C++.
- suffix form:
1+2i
- constructor form:
complex<double>(1,2)
then I tried different ways to add complex number
#include <iostream>
#include <complex>
using namespace std;
typedef complex<double> cd;
int main()
{
complex<double> a;
a=1+2i+3+4i; // working
a=cd(1,2)+cd(3,4); //working
a=1+2i+cd(3,4); //error
cout<<a;
return 0;
}
It outputs a lot of messages, and in the last line, it shows
mismatched types 'const std::complex<_Tp>' and '__complex__ int'
a=1+2i+cd(3,4);
What is wrong? Why can not add two different form of complex number?