C++ and in the same file

前端 未结 1 1390
轮回少年
轮回少年 2020-12-20 18:36

I have a large code base that uses the c++ header and many std::complex objects. But now I also want to use a couple

相关标签:
1条回答
  • 2020-12-20 19:15

    In C, _Complex is a keyword used to declare complex numbers: float _Complex. However, they #define complex _Complex so you can write float complex which looks nicer.

    Of course, you get in trouble when using the name complex in a context other than where you want _Complex, such as std::complex, which then expands to std::_Complex.

    So if you use <complex> in C++, you should get rid of this macro:

    #include <complex.h>
    #undef complex
    

    That's actually what g++ does since 4.8 to support both <complex> and <complex.h> in the same translation unit.

    Note that when enabling C++11, you won't get the error either.

    0 讨论(0)
提交回复
热议问题