20-CS-122-001 Computer Science II Spring 2012
Overloading ++ and --

Virtual functions, classes, inheritance, lists, queues, stacks, applications

Prev      Next      Lectures

Special because they are used as postfix or prefix operators

   Prefix:

       type ClassA::operator++();      // as a class member

       type operator++(type arg);      // as a non-member

   Postfix:

       type ClassA::operator++(int);   //  int signifies postfix

       type operator++(type arg, int); //  int signifies postfix

   Example:

       Fraction Fraction::operator++() {  // preincrement
          num += denom;
          return *this;
       }