如何从枚举中删除标记 p>
我可以使用m_Buttons | (button);
enum WindowButton
{
None = 0,
Minimize = (1 << 0),
Maximize = (1 << 1),
Close = (1 << 2),
};
inline WindowButton operator|(WindowButton a, WindowButton b)
{
return static_cast<WindowButton>(static_cast<int>(a) | static_cast<int>(b));
}
inline WindowButton& operator |= (WindowButton& lhs, WindowButton rhs)
{
return lhs = static_cast<WindowButton>(static_cast<WindowButton>(lhs) | static_cast<WindowButton>(rhs));
}
这是我试图添加/删除
的功能void Window::SetButton(WindowButton button, bool show)
{
if (show)
m_Buttons |= (button);
else
m_Buttons | ~(button); // This is not working to remove flags
}
答案 0 :(得分:4)
m_Buttons | ~(button); // This is not working to remove flags
当然不是。它设置应该清除的位置,然后丢弃结果。应该是
m_Buttons &= ~button;
NB括号在这里是多余的。