-1
看到這個非常簡單的代碼:==操作符()循環永遠
struct A
{
bool operator ==(const int &t)
{
return *this == t;
}
};
void main()
{
A p;
p == 2;// this code loops for ever!!!
}
劑量任何一個知道爲什麼代碼循環永遠! 實際上運算符==()會遞歸地調用它自己!
非常感謝
因爲'* this == t'與'p == 2' =>調用操作符'=='在左邊的struct A和右邊的int之間 – Garf365
提示:執行'* this時會發生什麼== t'? – milleniumbug
'* this == t'等於'this.operator ==(t)'。 – Yves