C++ Overloading Operators

   C++ overloading clearly advocates simplicity in usage and readability. That is why all forms of operators are getting overloaded to give natural and domain oriented meanings. 
   The increment operator ++ can be called in two forms post fix and pre fix. The programmers will have a slight difficulty in overloading/using it because, they won't know how to differentiate them. That is why postfix operators are created with a dummy parameter of type int. 
   The prefix ++ operator can be overloaded as such, without any change. Look at the function/operator definition.


   Class Test 
   {
       int i;
     public:
       void operator ++() 
       { 
            ++i;
       }
    };


   The post fix ++ operator will be overloaded with a dummy integer parameter as follows. 
   Class Test 
   {
      int i;
    public:
      void operator ++(int)
      {
          i++;
      }
    };


   Similar method of overloading is used for the -- post/prefix operators also. 
   The stream operators << and << need a different type of treatment. Though these kind of techniques make the life of the developer difficult, it is the user who is going to be benefited the most.

Close    To Top
  • Prev Article-Programming:
  • Next Article-Programming:
  • Now: Tutorial for Web and Software Design > Programming > cplus > Programming Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction