The following code compiles and runs just fine in C (at least according to 'gcc -std=gnu99'), but it fails to compile under C++, giving "line 5: error: cannot convert 'double' to 'double complex' in initialization". Does anybody know why?
#include "/usr/include/complex.h"
#include <stdio.h>
int main(int argc, char * argv[]) {
double complex a = 3; // ERROR ON THIS LINE
printf("%lf
", creal(a));
return 0;
}
I realize there is another way of doing complex numbers in C++, but I have to use C complex numbers in C++, because that is how the legacy code I was given does things. Thanks if you can help!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…