Operator Overloading in C++

Operator Overloading

Source code :


#include <iostream>

using namespace std;

class temp{
  
public:
   
    int value;
    
    temp():value(7){}
   	
    void operator ++() { 
        value = value+1; //user defined value
    }
    
    void print(){ 
        cout <<"Count: "<< value; 
   	}
};


int main(){
    
    temp t;
    ++t;        /*  function void operator ++() is called */
    t.print();
    
    return 0;
}

Output :

Count :8

Notes :

Whenever the void operator ++() function is called,the value gets incremented by one.


Output :


                

Comments :