简体   繁体   中英

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

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'

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

To call the standalone function of the same name, prefix the call with the :: scope operator:

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

Otherwise, rename the standalone function to something more unique.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM