Can enum class be nested?

后端 未结 4 1997
[愿得一人]
[愿得一人] 2021-02-14 17:32

Can this be done?

enum A
{
    enum B
    {
        SOMETHING1,
        SOMETHING2
    };

    enum C
    {
        SOMETHING3,
        SOMETHING4
    };
};
         


        
4条回答
  •  伪装坚强ぢ
    2021-02-14 18:28

    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.

提交回复
热议问题