有人可以向我解釋爲什麼我的重載++(預版本)沒有更新值?片段是這樣的:重載++運算符不在C++中工作
circle circle:: operator++()
{
Area = Area * 2.0;
return *this;
}
/////////////////////////////
int main()
{
class circle c1(4, 1, -1), c2(12, 4, 6);
c1.output();
c1++;
c1.output();
system("pause");
return 0;
}
你不是在調用postfix版本'c1 ++'嗎? – EdChum
此外,您需要檢查您的[簽名](http://en.cppreference.com/w/cpp/language/operator_incdec),因爲您的版本不匹配 – EdChum
增量後續簽名'c1 ++'需要您執行' circle&circle :: operator ++(int)'。你當前的'operator ++()'實現將用於預增'++ c1' – Vishal