This syntax:
tclass operator++()
is for prefix ++
(which is actually normally written as tclass &operator++()
). To distinguish the postfix increment, you add a not-used int
argument:
tclass operator++(int)
Also, note that the prefix increment better return tclass &
because the result may be used after: (++rr).x
.
Again, note that the postfix increment looks like this:
tclass operator++(int)
{
tclass temp = *this;
++*this; // calls prefix operator ++
// or alternatively ::operator++(); it ++*this weirds you out!!
return temp;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…