Flag

I have a vector of int value that i want set flag rather bool vaiable
an now i don't know how
I will pleased if you help me
thank you
closed account (zb0S216C)
I'm not quite sure what you're asking here but since you mentioned flags, I'm going to hazard a guess and say that you're referring to bit-masks:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
namespace Flags 
{
    typedef unsigned int Flag_Type;
    Flags::Flag_Type const FLAG_A(1 << 0);
    Flags::Flag_Type const FLAG_B(1 << 1);
    Flags::Flag_Type const FLAG_C(1 << 2);
    // ...
}

int main( )
{
    std::vector<Flags::Flag_Type> Flag_Vector;

    // Adding a flag or two:
    Flag_Vector.push_back(Flags::FLAG_A | Flags::FLAG_C);

    // Checking for a flag:
    if(Flag_Vector.front( ) & Flags::FLAG_B)
        // ...
}

If this is the sort of behaviour you're looking for, then I suggest the use of "std::bitset"[1].

Reference:
[1] http://www.cplusplus.com/reference/stl/bitset/


Wazzak
Topic archived. No new replies allowed.