Can enum class be nested?

后端 未结 4 1415
执笔经年
执笔经年 2021-02-14 17:33

Can this be done?

enum A
{
    enum B
    {
        SOMETHING1,
        SOMETHING2
    };

    enum C
    {
        SOMETHING3,
        SOMETHING4
    };
};
         


        
4条回答
  •  感情败类
    2021-02-14 18:32

    No, there is no way of doing this without defining everything in a long list inside one enum.

    enum class A{
      PARTICLE_MATTER_BARYON_PROTON,
      PARTICLE_MATTER_BARYON_NEUTRON,
      PARTICLE_ANTIMATTER_BARYON_PROTON // etc
    };
    

    If this doesn't make sense to you, then you are surely a physicist.

    I am accepting this as the answer to stop further notifications from stackoverflow asking me to accept an answer.

提交回复
热议问题