Subscribe Us

Responsive Advertisement

Advertisement

Overloading Increment and Decrement Operators in Prefix form OOP using friend function and member function

 

Overloading Increment and Decrement Operators in Prefix form OOP using friend function and member function



#include<bits/stdc++.h>

using namespace std;

class pre

{

    int val;

public :

       pre()

       {

           val=0;

       }

       pre(int v)

       {

           val=v;


       }

       void display()

       {


           cout<<val<<endl;

       }

       void operator++()

       {

           val=val+1;

       }

       friend pre operator--(pre &);


};

pre operator--(pre &v)

{

    v.val-=1;

}

int main()

{

  pre a(10);

   a.display();

  ++a;

  a.display();

  --a;

   a.display();



    return 0;

}


Post a Comment

0 Comments