c++ - How to initialise a std::map once so that it can be used by all objects of a class? -
i have enum stackindex defined follows:
typedef enum { deck, hand, cascade1, ... no_such_stack } stackindex; i have created class called movesequence, wrapper std::deque of bunch of tuples of form <stackindex, stackindex>.
class movesequence { public: void addmove( const tpl_move & move ){ _m_deque.push_back( move ); } void print(); protected: deque<tpl_move> _m_deque; }; i thought create static std::map member of movesequence class, translate stackindex std::string, use print() function. when tried, got error:
"error c2864: 'movesequence::m' : static const integral data members can initialized within class" if not possible created std::map static member, there way create std::map translates stackindex std::string can used print out movesequence objects?
thanks
beeband.
you can make std::map static member of class. can't initiliaze within class definition. note error telling you:
error c2864: 'movesequence::m' : static const integral data members can *initialized* within class
so, want have in header:
class movesequence { static std::map<stackindex, std::string> _m_whatever; }; and in source (.cpp) file want this:
std::map<stackindex, std::string> movesequence::_m_whatever( ..constructor args.. );
Comments
Post a Comment