I'm having trouble with the unary ++ overloaded operator.
Here is my code...
#include<iostream>
using namespace std;
class Index{
int value;
public:
Index() : value(0) { }
int GetIndex() const
{
return value;
}
void operator ++()
{
value++;
}
};
int main()
{
Index idx1,idx2;
++idx1;
idx2++;
idx2++;
cout << "idx1.value:" << idx1.GetIndex() << endl;
cout << "idx2.value:" << idx2.GetIndex() << endl;
}
The statement idx2++ is giving me a compilation error.The prefix however i.e ++idx1 is working properly.The book I'm referring to says that both should give the same output...i.e the value member must get incremented by 1.
Why am I facing this problem??...The IDE I'm using is visual studio 2015.