how do I allow free usage of enum and enum class member?

enum class A
{
  ORANGE,
  APPLE
};
...
{// workspace brackets

  if(B == ORANGE){...} // use it like this
}// end of workspace

instead of keep using B==A::ORANGE, what can I do to make it like B==ORANGE within my workspace such as using namespace std?

Upvotes: 0

Views: 48

Answers (1)

Raildex
Raildex

Reputation: 4727

You can only do this in c++ 20 onwards with using enum A

enum class foo {
    a,
    b,
    c
};
int main() {
    {
        using enum foo;
        foo f = b;
    }

    {
        //foo f = b; // does not compile
    }
}

Upvotes: 2

Related Questions