** Pre Increment **
#include <iostream>
using namespace std;
class demo {
int i;
public:
demo (int b = 0) {
i = b;
}
void display() {
cout<<"Number is " <<i<<endl;
}
void operator ++() {
i = ++i;
}
};
int main() {
demo obj(5);
obj.display();
++obj;
obj.display();
return 0;
}
In this case operator function took no function argument
** Post Increment **
#include <iostream>
using namespace std;
class demo{
int i;
public:
demo (int b = 0 ){
i = b;
}
void display(){
cout<<"Number is " <<i<<endl;
}
void operator++(int){
i = i++;
}
};
int main(){
demo obj(5);
obj.display();
obj++;
obj.display();
return 0;
}
While in this code the function took the int as and argument
In these codes almost everything is same except for the fact that in one code void operator ++() takes a argument int while in other it doesn't .
What could be the possible reason of such behaviour ?