无法将参数 1 从 'float *' 转换为 'CArray &'
Cannot convert argument 1 from 'float *' to 'CArray &'
我正在尝试将 FFT (this rosettacode.org C++ implementation of FFT : void fft(CArray &x) { ... }
, or should I use the C implementation ?) 应用于此数据给出的数组:
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 &'
如何解决这种错误?
您必须将数组转换为 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);
}
我正在尝试将 FFT (this rosettacode.org C++ implementation of FFT : void fft(CArray &x) { ... }
, or should I use the C implementation ?) 应用于此数据给出的数组:
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 &'
如何解决这种错误?
您必须将数组转换为 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);
}