调整大小时没有重载函数的实例

No instance of overloaded function when resizing

我在使用 resize() 时收到“没有重载函数实例”的错误。我知道 resize() 里面的内容也可能是错误的。我正在尝试将 x 的大小调整为全零的浮点数组。不确定 std::vector>(0, 0) 是否是正确的语法,因为我是 C++ 的新手。如何解决现有错误?

void IDFT(const std::vector<std::complex<float>> &Xf, std::vector<float> &x)
{
    // allocate space for the vector holding the frequency bins
    // initialize all the values in the frequency vector to complex 0
    x.resize(Xf.size(), static_cast<std::vector<float>>(0, 0));
    // Xf.resize(x.size(), static_cast<std::complex<float>>(0, 0));
    // "auto" keyword is used for type deduction (or inference) in C++
    for (auto k = 0; k < Xf.size(); k++)
    {
        for (auto m = 0; m < x.size(); m++)
        {
            std::complex<float> expval(0, 2 * PI * (k * m) / x.size());
            x[k] += x[k] * std::exp(expval);
        }
    }
}

这个:

x.resize(Xf.size(), static_cast<std::vector<float>>(0, 0));

应该是

x.resize(Xf.size());    // or x.resize(Xf.size(), 0.f); if you want to be explicit

还有这个:

x[k] += x[k] * std::exp(expval);

应该是:

x[k] += a_function_that_converts_a_complex_float_to_a_float(x[k] * std::exp(expval));

a_function_that_converts_a_complex_float_to_a_float 的实现留作练习。您可以随意使用 complex<float> 的成员函数 real()imag()