我如何從我的枚舉刪除標誌刪除逐位標誌
我可以添加他們很容易與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'。 –