How can I output the value of an enum class in C++11

前端 未结 7 2287
面向向阳花
面向向阳花 2020-11-30 19:00

How can I output the value of an enum class in C++11? In C++03 it\'s like this:

#include 

using namespace std;

enum A {
  a =          


        
7条回答
  •  借酒劲吻你
    2020-11-30 19:49

    You could do something like this:

    //outside of main
    namespace A
    {
        enum A
        {
            a = 0,
            b = 69,
            c = 666
        };
    };
    
    //in main:
    
    A::A a = A::c;
    std::cout << a << std::endl;
    

提交回复
热议问题