latest Post

C + + part - 8 ( Operator Overloading )








So hey this is the 8th part of the series which named as C + + and this is all about the Operator Overloading and this is also a  exciting topic if you want to learn and if you don't the other parts of this series you have don't go anywhere i have given link from 1st part to the 7th part and if you see them then you can understand so easily .
Not talk too much let's start....................................................................................................................

OPERATOR OVERLOADING 



IT IS JUST A CONCEPT BY WHICH WE CAN GIVE AN OPERATOR A SPECIAL MEANING.
THE LINKS OF THE PREVIOUS ARTICLES ARE BELOW : -








WE CAN OVERLOAD AN OPERATOR BY THE GIVEN TECHNIQUES THERE CAN BE MORE BUT THESE ARE BASIC ONE : -

[1] USING FRIEND FUNCTION
     Same number of parameters are passed in comparison  to actual .
     (i have explained the friend function  in my article so you can see there above the link is present)
[2] WHICH USING FRIEND FUNCTION
      One less parameters are passed in comparison to actual parameters .
IN THIS WE ARE DOING THE OPERATOR OVERLOADING OF THE BINARY ( << , >> ) OPERATOR USING FRIEND FUNCTION

CODE........................................................................................................................................................


#include<iostream.h>
#include<conio.h>
class abc
{
              int i ;
              public :
                           friend istream& operator>>(istream&in,abc&m)
                           {
                                                   in>>m , i ;
                                                   return in ;
                           }
                           friend ostream& operator<<(ostream&out,abc&m)
                           {
                                                   out<<m , i ;
                                                   return out ;
                           }
} ;
void main ( )
{
                    abc a;
                    cout<<"\n enter any number : " ;
                    cin>>a ;
                    cout<<"a="<<a;
                    getch ( ) ;
}

AND IF YOU HAVE ANY DOUBT REGARDING ANY ARTICLE WRITE IN THE COMMENT OR YOU CAN CONTACT ME BY THE CONTACT PAGE.
LET'S MEET IN THE ANOTHER ARTICLE THANKS FOR YOUR TIME WHICH HAVE BEEN TO THIS ARTICLE.
.......................................................................END.................................................................................


About hack guru

hack guru
Recommended Posts × +

0 comments:

Post a Comment