dr. salih yurttas - yurttas@cs.tamu.edu
programming languages - design principles, implementation constructs
c++

  1. abstraction mechanisms: classes and operator overloading
    1. class/object construction - operator overloading
      1. binary and unary operators -
        • example
        • 
          class A {
          // members (with implicit first argument: this) :
          
            A* operator& ();              // prefix unary & (address of)
          
            A  operator& (A);             // binary & (and)
          
            A  operator++ (int);          // postfix increment
          
            A  operator& (A,A);           // error: ternary
          
            A  operator/ ();              // error: unary /
          
          // global functions (often friends) :
          
            friend A operator- (A);       // unary minus
          
            friend A operator- (A,A);     // binary minus
          
            friend A operator-- (A&,int); // postfix decrement
          
            friend A operator- ();        // error: no operand
          
            friend A operator- (A,A,A);   // error: ternary
          
            friend A operator% (A);       // error: unary %
          };
          
          

        << | >>


1 | basic facilities << 3 >> class derivation | 5 | 6 | 7 | 8
computer science | texas a&m university

Valid XHTML 1.0 Transitional