#include <iostream>
using namespace std;
class B{
int temp1;
public :
void disp()
{
cout <<temp1;
}
void setA(int a)
{
temp1=a;
}
void operator ++(int)
{
temp1+=5;
}
void cal()
{
temp1 ++;
}
};
int main()
{
B b;
b.setA(10);
b.cal();
b.disp();
return 0;
}
I recently learned about operator overloading so playing around with code .....so the expected answer here is 15 but it is appearing as 11. Why is my overloaded operator not working...and specifically what is wrong with this code rsince there seems to be a logical error in this part:
void operator ++(int)
{
temp1+=5;
}
void cal()
{
temp1 ++;
}