I can't figure out how to implement a bitmask parameter for my class.
Specifically my CreateMenuDlg function
I've searched google quite a bit, finding all sorts of forum questions that ask about bitmasks, bitfields, etc. and everyone posts minimal example code
I keep finding people using #define but that wouldn't work for my class since I need to call it from main dialog with something like this:
DialogMenu *p_dlgMenu = new DialogMenu( this, &p_dlgMenu, this );
p_dlgMenu->CreateMenuDlg( ( DialogMenu::CLOSES | DialogMenu::WINDOW_HANDLER ), DialogMenu::DLG_CHECKOUT );
Here's my code:
class DialogMenu : public CDialog
{
DECLARE_DYNAMIC(DialogMenu)
public:
enum dlgFlags
{
HIDES = 2^0,
CLOSES = (2^0)+1,
WINDOW_HANDLER = 2^1,
MSG_HANDLER = (2^1)+1,
DLG_SHOPPING_MENU = 2^2,
DLG_DYNAMIC_MENU = (2^2)+1,
};
dlgFlags operator|=( dlgFlags first, flgFlags second)
{
return (dlgFlags)( (unsigned)first | (unsigned)second );
}
enum dlgType { DLG_CHECKOUT, DLG_INVENTORY_EDIT, DLG_SHIPPING_RECEIVING };
DialogMenu( CDialog * const, DialogMenu ** const, CWnd* pParent = NULL );
void PostNcDestroy();
virtual ~DialogMenu();
void CreateMenuDlg( dlgFlags paramFlags = ( CLOSES | MSG_HANDLER | DLG_DYNAMIC_MENU ), dlgType paramType = DLG_CHECKOUT );
protected:
virtual void DoDataExchange(CDataExchange * pDX);
CDialog * m_parent;
DialogMenu ** m_self;
};
For which I'm receiving errors from my bitmask enumeration not being int.
dialogmenu.h(21): error C2440: 'default argument' : cannot convert from 'int' to 'DialogMenu::dlgFlags'
Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)
But my OR operator overload should be taking care of that cast!
If I have to I'll abandon bitflags altogether, but I'm trying to get the hang of them and I get more points on my project per C++ subject covered and bitfields was the most recent thing we learned. (Although we never learned how to implement them as enumerations, only playing with them on character variables.)