Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ Language Reference - operator overloading _ http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
                           Operator Overloading                       _
   The  C++  language provides the facility to connect  a  user  provided
   function to the standard operators so that the function is called when
   the  compiler  observes  this operator in a  specified  context.  This
   facility is known as operator overloading.

   In  order  to  qualify  as an operator  function,  the  user  supplied
   function  must take at least one class argument. This means that  void
   functions  and functions that have only base data types  as  arguments
   cannot  be used as operator functions. This restriction  prevents  the
   behavior  of  a C++ operator from being changed with  respect  to  the
   basic data types.

   The syntax for declaring an operator function is as follows:
   return_type operator op(argument list)
   where op is one of the following C++ operators:
   Overloadable Operators

        +    -    *    /    %        &    |
        ~    !    ,    =    <    >    <    =    >    =
        ++   --   <<   >==  !=   &&   ||
        +=   -=   /=   %=   =   &=   |=   <<=
        >=   []   ()   ->   new  delete

   The  pre-defined  precedence of the C++ operators  cannot  be  changed
   except by the use of parentheses.

   Operator functions are normally used within classes to facilitate  the
   implementation  of a user defined data type. The operators =, [],  ->,
   (),  new  and delete must be defined as class  member  functions.  All
   other operators can be defined either as a class member function or as
   a  friend  function:  it  is usual to  define  them  as  class  member
   functions.


Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson