Flags, enum (C)

后端 未结 6 1587
既然无缘
既然无缘 2021-02-02 14:54

I\'m not very used to programming with flags, but I think I just found a situation where they\'d be useful:

I\'ve got a couple of objects that register themselves as lis

6条回答
  •  萌比男神i
    2021-02-02 15:30

    Yes. Instead, make your enum members powers of 2:

    enum
    {
        TAKES_DAMAGE = (1 << 0),
        GRABBABLE = (1 << 1),
        LIQUID = (1 << 2),
        SOME_OTHER = (1 << 3)
    };
    

提交回复
热议问题