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 p2);
                            friend Values operator++(Values &p);
                            friend Values operator-(Values &p);
};
                           Values Values::operator=(Values p2)
            {
                           a =p2.a;
                           b =p2.b;
                           return *this;
                 }
                          //friend;use a reference.
                          Values operator++(Values &p)
                 {
                           p.a++;
                           p.b++;
                           return p;
                 }
                           //lip- a friend;use reference
                           Values operator-(Values &p)
                {
                            p.a--;
                            p.b--;
                            return p;
                 }
                            void main()
        {
                            clrscr();
                            Values v1 (20,30),v2;
                            v1.show(); 
                            ++v1;
                            v1.show();
                            v2 =++v1 ;
                            v2.show();
                            -v2;
                             v2.show();
                             getch();
         }

Overload ++ or - -

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.



Search Content





Popular Article