如何重载接受相同数量参数但返回类型不同的减号运算符?
模板类:
template <typename T>
T minus (T x, T y) {
return (x - y);
}
template <typename T>
double absMinus (T x, T y) {
double sd = abs(x - y);
return sd;
}
运算符重载类:
Minus operator-(Minus &p, Minus &q) {
return (p.something - q.something);
}
double operator-(Minus &p, Minus &q) {
return (p.something() - q.something());
}
当我尝试编译时,它给了我以下错误:
Minus.h:25: error: new declaration ‘double operator-(Minus&, Minus&)’
Minus.h:24: error: ambiguates old declaration ‘Minus operator-(Minus&, Minus&)’