Assigning values to an enum has (under certain circumstances) great value.
If you have set up an enum in a binary escalating scale (1,2,4,8,16 etc) and
you also wish to use it in a loop then use the bitwise shift operator as
follows:
#include <conio>
#include <iostream>
enum state {none = 1, open =2, modified = 4, deleted = 8};
int main(int argc, char* argv[])
{
for (int i=1; i<=deleted; i<<=1)
{
std::cout << "did something\n";
}
getch();
return 0;
}
Now it is possible to loop through each state and do something as well as
use logical operators to combine the different states using the bitwise or
operator, e.g..
fileState |= modified;
Graeme.
|