我如何从我的枚举删除标志删除逐位标志
我可以添加他们很容易与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
}
使用'|'而不是'| ='意味着'm_Buttons'不会被修改......但是'| ='也不是正确的。 – hvd
提示:在“flags | = f”上转换一个位标记。关闭一个bitflag:'flags&=〜f'。 –