我是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