Operator Overloading
#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; }
Count :8
Whenever the void operator ++() function is called,the value gets incremented by one.
Comments :