Huy Vũ Quang

29 bundles
1 filea month ago
1

Prefix vs Postfix operator

Number.h

12345678910111213141516
class Number { public: Number& operator++ () // prefix ++ { // Do work on this. (increment your object here) return *this; } Number operator++ (int) // postfix ++ { Number result(*this); // make a copy for result ++(*this); // Now use the prefix version to do the work return result; // return the copy (the old) value. } };