0

I can't figure our how to pass multiple bit values of enum class and check them inside function. I have the following code:

enum class BitFlags
{
    Write,
    Read,
    NumOfFlags
};

void update(BitFlags flags)
{
    // Figure out if Write and Read flags are set
}

Trying to make

update(BitFlags::Read | BitFlags::Write);

does not work. Appreciate any help. Thanks.

Oleg
  • 1,027
  • 1
  • 8
  • 18
  • 2
    Enum class might not be the best choice here. You need to explicitly cast everything to int first. – Yksisarvinen Nov 09 '20 at 11:17
  • The enum class can only have one value, thus you can't have Read and Write at the same time in your case. (It can't be used to contain a bit pattern) – ttemple Nov 09 '20 at 11:28
  • emum class is more appropriate as a state variable in a state machine where you can only be in one state at a time. If you only have several values, you could combine (read, read_write, write) – ttemple Nov 09 '20 at 11:31

0 Answers0