by Dinesh Thakur Category: Classes in C++

 

#include <iostream.h>

#include<conio.h>
class Values
{
       int a,b;
       public:
                    Values(){}
                    Values(int aa,int bb)
              {
                    a=aa;
                    b=bb;
              }
                   void show()
             {
                   cout <<a <<" ";
                   cout <<b <<"\n";
             }
                 Values operator+(Values p);
};
                Values Values::operator+(Values p)
          {
                Values temp;
                temp.a =p.a +a;
                temp.b =p.b +b;
                return temp;
          }
                 void main()
           {
                 clrscr();
                 Values v1(20,30),v2(15,40);
                 v1.show();
                 v2.show();
                 v1 =v1 +v2;
                 v1.show();
                getch();
          }

definition of operator+ ( )



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles