I am new in C++ and I've got some questions. I saw operator ++ overloading at complex numbers and I cant understand:
- Why I create a
tmpvariable - why my first operator is
Complex &and second it's justComplex - Why return *this;(i know cause of
Complex&but why) - if i used Complex without & what would happened?(i run it and its the same result)
Don't look at comments it's Greek :)
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//
}