调整大小时,没有重载函数的实例 [英] No instance of overloaded function when resizing

查看:56
本文介绍了调整大小时,没有重载函数的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到了没有重载函数实例"的错误消息.当我使用resize()时.我知道resize()内部的内容也可能是错误的.我正在尝试调整x的大小,此数组是一个浮点数到全零的数组.不知道std :: vector>(0,0)是否是正确的语法,因为我对C ++很陌生.如何解决现有错误?

I got an error of "No instance of overloaded function" when I used resize(). I'm aware that what's inside of resize() might be wrong as well. I'm trying to resize x, an array of floats to all zeros. Not sure if std::vector>(0, 0) would be the right syntax for it as I am very new to C++. How do I solve the existing error?

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().

The implementation of a_function_that_converts_a_complex_float_to_a_float is left as an exercise. You have the complex<float>'s member functions real() and imag() at your disposal.

这篇关于调整大小时,没有重载函数的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆