Problem casting STL complex to fftw_complex

前端 未结 3 1613
鱼传尺愫
鱼传尺愫 2020-12-28 08:25

The FFTW manual says that its fftw_complex type is bit compatible to std::complex class in STL. But that doesn\'t work for me:

<
3条回答
  •  误落风尘
    2020-12-28 09:04

    reinterpret_cast only works for pointers and references. So you'd have to do this:

    #include 
    #include 
    int main()
    {
       std::complex x(1,0);
       fftw_complex fx(*reinterpret_cast(&x));
    }
    

    This assumes that fftw_complex has a copy constructor. To avoid problems with strict aliasing, Goz's solution should be preferred.

提交回复
热议问题