pree or post operator overloading

Code:

#include<iostream>
using namespace std;
class complex{
protected:
    int x,y;
public:
    complex(){x=0,y=0;}
    complex(int x,int y){
        this->x=x;
        this->y=y;
    }void show(){cout<<x<<'+'<<y<<'i'<<endl;}
    complex operator++(){
        ++x;
        ++y;
        return *this;
    }
    complex operator++(int ){
        complex temp;
        temp.x=x++;
        temp.y=y++;
        return temp;
    }
};
int main()
{
    complex ob1(2,4),ob2,ob3(2,4);
    ob1.show();
    ob2=++ob1;
    cout<<"After pree increment: "<<endl;
    ob1.show();
    ob2.show();
    ob2=ob3++;
    cout<<"After post increment: "<<endl;
    ob1.show();
    ob2.show();
    return 0;
}


মন্তব্যসমূহ

এই ব্লগটি থেকে জনপ্রিয় পোস্টগুলি

Big Big mod

শিরোনামহীন গল্প

Dictionaries and Maps