I have an array of complex floats that I'm working with in C++11:
std::complex<float> *cx;
I am trying to use an older library which takes in C style complex floats:
float complex *cx;
When I try this:
std::complex<float> *cpp = new std::complex<float>[100];
complex float *c = reinterpret_cast<complex float*>(cpp);
c_process(c); // c_process(complex float *c) [ c library function ]
I get:
error: expected ';' before 'float'
complex float *c = reinterpret_cast<complex float*>(cpp);
^
The problem is that the C library's headers contains #include <complex.h>
, and I have #include <complex>
in my C++11 code which uses std::complex.
class complex
from <complex>
and #define complex _Complex
from <complex.h>
seem to be clashing on the word complex
.
One Solution:
This solution only works if you can modify the other library's headers.
Since the powers at be closed this question (although I think it's a pretty good), here's what I did:
Since <complex.h>
has a #define complex _Complex
and <complex>
contains a class complex
, there is some conflict when including both headers.
I had to change all float complex*
to float _Complex*
everywhere in my code and other library's header files. This removed the clash on the word complex
from the cstyle <complex.h>'s define and c++ style's class complex without changing what the code does.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…