C++ Overloading Operators

CoderSource.net
C++ Overloading Operators
Rating:

Date: 5/1/2004 12:00:00 AM

   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.

You Can Rate this Article, if you are Logged In      
 

More Links from CoderSource.net:

 
Refer to a Friend:

Your Details:

Name:     e-mail:

Friend Details:

Name:    e-mail:    


MENU
Home
MFC 
C++
.Net
WIN32
Programming
Forum
My Articles
Add to Google
Add to My Yahoo!
Welcome to Codersource.Net Login | Register | Faq  

SEARCH
Google
 

NOTES:


Thanks for visiting our CoderSource.net. This site will be improved with more articles. Interested visitors can also submit their articles through the Submit Article link.Your article will also be published after due consideration by the editor. 

© Copyright 2003. All rights on content reserved by CoderSource.net. Contact    About Us