无法将参数 1 从 'float *' 转换为 'CArray &'

Cannot convert argument 1 from 'float *' to 'CArray &'

本文关键字:转换 CArray float 参数      更新时间:2023-10-16

我正在尝试将FFT(此rosettacode.org c++实现的FFT: void fft(CArray &x) { ... },或者我应该使用C实现吗?)应用于由此数据给出的数组:

float *x
VstInt32 sampleFrames    // basically the length of the array

当我这样做的时候:

fft(x);

我得到:

error C2664: 'void fft(CArray &)' : cannot convert argument 1 from 'float *' to 'CArray &'

如何解决这种错误?


您必须将数组转换为数组类型别名:

http://coliru.stacked-crooked.com/a/20adde65619732f8

typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
void fft(CArray& x)
{   
}
int main()
{
    float sx[] = {1,2,3,4};
    float *x = sx;
    int sampleFrames = sizeof(sx)/sizeof(sx[0]);
    // Convert array of floats to CArray
    CArray ca;
    ca.resize(sampleFrames);
    for (size_t i = 0; i < sampleFrames; ++i)
      ca[i] = x[i];
    // Make call
    fft(ca);
}