简体   繁体   English

错误:没有匹配的 function 调用“进程” <std::vector<double> &gt;::minmax(const std::vector<double> &amp;,标准::向量<double> &amp;) 常量'| </double></double></std::vector<double>

[英]error: no matching function for call to 'Processus<std::vector<double> >::minmax(const std::vector<double>&, std::vector<double>&) const'|

I have a problem, I have my class and my minmax function coded as below我有一个问题,我的 class 和我的 minmax function 编码如下

template<typename T>
class Processus {
public:
    typedef pair<double, T> state;
    typedef vector<state> result_type;

    Processus(int n = 0) : v(n+1)
    {
        Schedule w(n);
        auto i_w = w.begin();
        for (auto it = v.begin(); it != v.end(); ++it, ++i_w) it->first = *i_w;
    };
    Processus(const Schedule& w) : v(w.size()) {
        auto i_w = w.begin();
        for (auto it = v.begin(); it != v.end(); ++it, ++i_w) it->first = *i_w;
    }
    ~Processus() {};
    virtual result_type operator()() = 0;

    auto begin() const { return v.begin(); };
    auto end() const { return v.end(); };

    pair<T, T> minmax() const;

protected:
    vector<state> v;
};
    
pair<vector<double>, vector<double>> minmax(const vector<double>& v1, const vector<double> v2){
    pair<vector<double>, vector<double>> cur(v1, v2);
    auto i_min = cur.first.begin(), i_max = cur.second.begin();
    for (auto it = v1.begin(), it2 = v2.begin(); it != v1.end(); ++it, ++it2, ++i_min, ++i_max) {
        *i_min = ::min(*it, *it2);
        *i_max = ::max(*it, *it2);
    }
    return cur;
}


template<>
inline pair<vector<double>, vector<double>> Processus<vector<double>>::minmax() const {
    pair<vector<double>, vector<double>> cur(begin()->second, begin()->second);
    for (auto it = begin()+1; it != end(); ++it) {
        cur.first = minmax(it->second,cur.first).first;
        cur.second = it->second.minmax(cur.second).second;
    };
    return cur;
};

However, I get the error:但是,我收到错误:

error: no matching function for call to 'Processus<std::vector<double> > >::minmax(const std::vector<double>&, std::vector<double>&) const'错误:没有匹配的 function 调用 'Processus<std::vector<double> >::minmax(const std::vector<double>&, std::vector<double>&) const'

Which correspond to this line:对应于这一行:

cur.first = minmax(it->second,cur.first).first;

Inside of Processus::minmax() , your intent is to call your standalone 2-parameter minmax() function.Processus::minmax()内部,您的意图是调用独立的 2 参数minmax() function。 However, from the error message, it is clear that the compiler is trying to call Processus::minmax() recursively instead, which does not work since Processus::minmax() does not take in any parameters.但是,从错误消息中可以清楚地看出,编译器正在尝试以递归方式调用Processus::minmax() ,这不起作用,因为Processus::minmax()不接受任何参数。

To call the standalone function of the same name, prefix the call with the :: scope operator:要调用同名的独立 function,请在调用前加上:: scope 运算符:

cur.first = ::minmax(it->second,cur.first).first;

Otherwise, rename the standalone function to something more unique.否则,将独立的 function 重命名为更独特的名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:没有匹配的 function 调用 'recherche(std::vector &gt;&amp;, std::vector &gt;::iterator, std::vector &gt;::iterator, const char [10])' - error: no matching function for call to ‘recherche(std::vector >&, std::vector >::iterator, std::vector >::iterator, const char [10])’ 错误:没有匹配的 function 调用 'std::vector<float> ::push_back(std::vector<float> &amp;) 常量'</float></float> - error: no matching function for call to 'std::vector<float>::push_back(std::vector<float>&) const' 编译器试图实例化std :: vector <double const> 没有明显的原因 - Compiler trying to instantiate std::vector<double const> for no obvious reason 取消引用不适用于std :: vector <std::vector<double> &gt; - Dereferencing not working for std::vector<std::vector<double> > 分配给std :: vector <std::vector<double> &gt;并行 - Assigning to std::vector<std::vector<double>> in parallel 转换一个std :: vector <boost::optional<double> &gt;到std :: vector <double> - Convert a std::vector<boost::optional<double>> to a std::vector<double> 转换 std::vector <std::vector<std::string> &gt; 到 std::vector <std::vector<double> &gt; - Converting std::vector<std::vector<std::string>> to std::vector<std::vector<double>> std :: vector的有效子集<double> - Efficient subset of a std::vector<double> 有效地将std :: stringstream数据解析为std :: vector <std :: vector <double >> - Efficient parsing of std::stringstream data into std::vector<std::vector<double>> boost :: transitive_closure()和“错误:没有匹配的函数来调用&#39;vertices(const std :: vector <std::vector<long unsigned int> ……” - boost::transitive_closure() and “error: no matching function for call to ‘vertices(const std::vector<std::vector<long unsigned int>…”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM