S
Saeed Amrollahi
Dear all
I am struggling with a problem that's simple per se.
I have an enum and a prefix ++ operator:
enum Dir { North = 1, East = 2, South = 3, West = 4, Max_ = 5 }; //
clockwise
Dir operator++(Dir d)
{
Dir dd;
switch (d) {
case North:
dd = East;
break;
case East:
dd = South;
break;
case South:
dd = West;
break;
case West: // wrap
dd = North;
break;
};
return dd;
}
void f()
{
for (Dir d = North; d < Max_; ++d)
// do something
}
The problem is: in the above loop the ++ doesn't work,
indeed the loop is infinite. If you replace // do something with
output statement, it prints 1 forever.
It is really annoying.
please throw a ligth.
Regards,
-- Saeed Amrollahi
I am struggling with a problem that's simple per se.
I have an enum and a prefix ++ operator:
enum Dir { North = 1, East = 2, South = 3, West = 4, Max_ = 5 }; //
clockwise
Dir operator++(Dir d)
{
Dir dd;
switch (d) {
case North:
dd = East;
break;
case East:
dd = South;
break;
case South:
dd = West;
break;
case West: // wrap
dd = North;
break;
};
return dd;
}
void f()
{
for (Dir d = North; d < Max_; ++d)
// do something
}
The problem is: in the above loop the ++ doesn't work,
indeed the loop is infinite. If you replace // do something with
output statement, it prints 1 forever.
It is really annoying.
please throw a ligth.
Regards,
-- Saeed Amrollahi