可能重複:
Operator overloading
Operator overloading : member function vs. non-member function?爲什麼重載operator <作爲成員函數是不好的做法?
經過多年的明顯濫用這種構造有人向我指出,這是不好的做法:
class SomeClass
{
...
bool operator<(const SomeClass& other) const;
};
而這是很好的做法:
class SomeClass
{
...
};
bool operator<(const SomeClass& a, const SomeClass& b);
但我不能爲我的生活弄清楚爲什麼,找不到任何文檔上的差異。任何人都可以將我指向正確的方向嗎?
請參閱http://stackoverflow.com/questions/4622330/operator-overloading-member-function-vs-non -member-function – dirkgently 2012-04-25 03:29:18
謝謝,我猜測我是專門搜索比較運算符並錯過它。 – smocking 2012-04-25 03:31:29
[會員與非會員之間的決定](http://stackoverflow.com/questions/4421706/operator-overloading/4421729#4421729)。 – 2012-04-25 03:36:14