我是C++新手,我有一些問題。我看到operator ++
超載在複雜的號碼,我無法理解:++ operator overload C++含義
- 爲什麼我創建了一個
tmp
變量 - 爲什麼我的第一家運營商是
Complex &
和第二它只是Complex
- 爲什麼返回*本;(我知道原因的
Complex&
偏偏) - ,如果我使用複雜而不&發生了什麼會嗎?(我運行它和它相同的結果)
別看評論這是希臘:)
Complex & Complex::operator ++(){
r=r+1;
return *this;//to this einai to pointer tou trexontos alla 8eloume dereference ara vazoume *this gia na epistrepsoume refernce//
}
Complex Complex::operator ++(int){
Complex tmp(*this);
operator ++();
return tmp;//ftiaxnoume ena tmp tou antikimenou pou exoume meta efarmozoume to operator++ kai epistrefoume to tmp//
}
請參閱http://stackoverflow.com/a/4445969/78845,瞭解C++中的前後增量運算符的解釋。 – Johnsyweb 2014-11-24 22:51:40
[Post-increment和Pre-increment概念?]可能的重複(http://stackoverflow.com/questions/4445706/post-increment-and-pre-increment-concept) – Johnsyweb 2014-11-24 23:00:08