C++ 错误:对';的调用没有匹配函数;过程<;标准::向量<;双倍>>;::最小值(const std::vector<;double>;,std::vector<;double>;)const'|

C++ 错误:对';的调用没有匹配函数;过程<;标准::向量<;双倍>>;::最小值(const std::vector<;double>;,std::vector<;double>;)const'|,c++,C++,我有一个问题,我的类和我的minmax函数编码如下 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.

我有一个问题,我的类和我的minmax函数编码如下

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;
};

Processus::minmax()
内部,您的目的是调用独立的2参数
minmax()
函数。但是,从错误消息中可以明显看出,编译器正在尝试递归调用
Processus::minmax()
,这不起作用,因为
Processus::minmax()
不接受任何参数

要调用同名的独立函数,请在调用前加上
::
范围运算符:

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

否则,将独立函数重命名为更独特的函数。

Processus::minmax()
的内部,您的目的是调用独立的2参数
minmax()
函数。但是,从错误消息中可以明显看出,编译器正在尝试递归调用
Processus::minmax()
,这不起作用,因为
Processus::minmax()
不接受任何参数

要调用同名的独立函数,请在调用前加上
::
范围运算符:

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

否则,请将独立函数重命名为更独特的函数。

此代码很难阅读,您确实应该引入一些
typedef
使用
语句来清理它,但当有人告诉您更改代码时,请不要惊慌。现在将别名放在那里,但它们仅在类的作用域中定义。当您修改代码时,请确保它仍然产生相同的错误。现在未声明
T
。@Elezan为了避免类似的错误,您可能希望通过现有的许多联机编译器之一运行代码以检查错误。就我个人而言,我喜欢。这个代码很难阅读,你真的应该引入一些
typedef
使用
语句来清理它。当有人告诉你要更改代码时,请不要惊慌。现在将别名放在那里,但它们仅在类的作用域中定义。当您修改代码时,请确保它仍然产生相同的错误。现在未声明
T
。@Elezan为了避免类似的错误,您可能希望通过现有的许多联机编译器之一运行代码以检查错误。就我个人而言,我喜欢。这不应该是
std::minmax
?@Paul不,不应该是。仔细阅读代码,它在
Processus::minmax()方法的定义之上定义自己的
minmax()
函数。代码没有尝试使用,这是一个完全不同的函数哦,对了,我错了。谢谢大家!:)不应该是
std::minmax
?@Paul不,不应该是。仔细阅读代码,它在
Processus::minmax()方法的定义之上定义自己的
minmax()
函数。代码没有尝试使用,这是一个完全不同的函数哦,对了,我错了。谢谢大家!:)
cur.first = minmax(it->second,cur.first).first;