I have a problem with my c++ program.
I created a class that represents modulo number.
Let's say it looks like:
template <typename Type> class Cycler
{
public:
Cycler(Type Mod) : CurrentIndex(0), Mod(Mod)
{}
Cycler & operator ++ ()
{
F();
return *this;
}
Type operator ++ (int)
{
F();
return CurrentIndex;
}
Cycler & operator -- ()
{
B();
return *this;
}
Type operator -- (int)
{
B();
return CurrentIndex;
}
operator Type()
{
return CurrentIndex;
}
protected:
void F()
{
if((++CurrentIndex) == Mod)
CurrentIndex = 0;
}
void B()
{
if(CurrentIndex == 0)
CurrentIndex = Mod - 1;
else
CurrentIndex--;
}
Type CurrentIndex, Mod;
};
But let's say I'm doing:
Cycler<unsigned int> C(100);
unsigned int I1 = C; // IS 0, OK
I1 = ++C; //Is 1 - OK
I2 = C++; //Is 2 - NOT OK
If i do:
...
I2 = C;
C++;
//It is ok
I think this is a problem with oreder of operators executed - my number is incremented after ++, but before being casted to unsigned int.
How can I make this work?