c++ - Bitmask as member enum with default parameter -


i can't figure out how implement bitmask parameter class.

createmenudlg function

i've searched google quite bit, finding sorts of forum questions ask bitmasks, bitfields, etc. , posts minimal example code
i keep finding people using #define wouldn't work class since need call main dialog this:

dialogmenu *p_dlgmenu = new dialogmenu( this, &p_dlgmenu, ); p_dlgmenu->createmenudlg( ( dialogmenu::closes | dialogmenu::window_handler ), dialogmenu::dlg_checkout ); 

here's 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;   }; 


i'm receiving errors bitmask enumeration not being int.

dialogmenu.h(21): error c2440: 'default argument' : cannot convert 'int' 'dialogmenu::dlgflags' conversion enumeration type requires explicit cast (static_cast, c-style cast or function-style cast) 


or operator overload should taking care of cast!

if have i'll abandon bitflags altogether, i'm trying hang of them , more points on project per c++ subject covered , bitfields recent thing learned. (although never learned how implement them enumerations, playing them on character variables.)

this not or operator enum dlgflags, instead it's operator|= dialogmenu (having 3 operands including *this, doesn't compile):

dlgflags operator|=( dlgflags first, flgflags second) {     return (dlgflags)( (unsigned)first | (unsigned)second ); } 

change to

friend dlgflags operator|(dlgflags first, dlgflags second) {     return (dlgflags)( (unsigned)first | (unsigned)second ); } 

friend keyword needed make not member of dialogmenu. i'd prefer move out of dialogmenu class enum dlgflags itself:

enum dlgflags {     hides = 2^0,     // ... };  dlgflags operator|(dlgflags first, dlgflags second) {     return (dlgflags)( (unsigned)first | (unsigned)second ); }  class dialogmenu : public cdialog {      // ... } 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -