Hello
I'd like to store a templated class (handler) in a container..
The simplified design of handler class:
Now the problem is I dont know what would be proper way to store more objects of handler class in a map container since you have to dynamically allocate memory to be able to store the function in a class.Code:class handler_base { public: virtual ~handler_base() { } virtual void callback( ) = 0; }; template <typename T> class handler : public handler_base { public: handler(T h) : m_handler(h) { } ~handler() { } void callback() { std::cout << "okay\n"; //here I call bind on m_handler } private: T m_handler; };
I've been thinking about having boost::map_ptr container or just ordinary map but with smart (shared_ptr) pointer..
For instance:
What do you guys think would be best way? Maybe any other better implementation for that kind of design?Code:std::map<int, boost::shared_ptr<handler_base> > somemap; somemap.insert(3, new boost::shared_ptr<handler_object>(arguments));



LinkBack URL
About LinkBacks



CornedBee