which one of the two codes is right and why ?
C C::operator++() {
x++;
y++;
return *this;
}
C & C::operator++() {
x++;
y++;
return *this;
}
Thanks
The second one is the idiomatic one: a parameter-less operator++
is the pre-fix increment operator, which should return a reference to self.
Both are "correct", but the second is idiomatic, because it's expected that the prefix operator ++
returns an lvalue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With