[英]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.