C++ Program to demonstrate overloading of pre-increment operator [DEVCPP/GCC]

PROGRAM

//Program to demonstrate overloading of pre-increment operator

# include <iostream>

using namespace std;

class complex
{
int real,imag;

     public:

     complex()
{
real=0;imag=0;
}

     complex(int x,int y)
{
real=x;imag=y;
}

void show()
{
cout<<"Complex number is:"<<real<<"+"<<imag<<"i";
}

      complex operator++()      //operator overloading code
{                                    
complex temp;
temp.real= ++real;      
temp.imag= ++imag;
return temp;
}
};

int main()
{
complex c1(1,2),c3;
c3=++c1;     //c1.operator++()
c3.show();
return 0;
}

OUTPUT


Share this

Related Posts

FIND US ON FACEBOOK!