ねえ、私はこれらの2つの演算子定義の違いを知りたいです:
1:
class Rational{
//...
public:
//...
Rational operator -() const{ return Rational(-t,b);}
//...
};
2:
class Rational{
//...
public:
//...
friend Rational operator -(const Rational& v) {return Rational(-t,b);}
//...
};
私が理解している限り、以下の使用法について:
Rational s = -r
r.operator-() // should happen
違いについて説明をお願いします、ありがとう!