Trouble getting boost::ptr_container::ptr_map working
Hello, I'm writing an small library to represent types. Right now I'm focusing on representing type composition. For that I'm using the composite pattern as proposed by Gamma et al., so I have an abstract base class for my composites that has the virtual functions to addComposite members, but not their implementation. The header of my class looks like this: namespace dintype { class Type{ public: virtual ~Type()=0; typedef std::string Name_t; virtual void addComposition(const Name_t& name,Type* tp)=0; virtual void delComposition(const Name_t& name)=0; Type* clone() const; protected: typedef ptr_map<Name_t,Type> children_t; typedef children_t::iterator children_iterator; typedef children_t::const_iterator children_const_iterator; typedef children_t::size_type children_size_type; Type(); private: virtual Type* do_clone() const=0; }; inline Type* new_clone(const Type& c) { return c.clone(); } } The one for my composite class is: class CompositeType : public Type { private: children_t m_children; CompositeType(const CompositeType& r); virtual Type* do_clone(); protected: void clearAllCompositeChildren(); public: CompositeType(); virtual ~CompositeType(); virtual void addComposition(const Name_t& name,Type* tp); virtual void delComposition(const Name_t& name); }; Here is the implementation of the composite class: CompositeType::CompositeType(const CompositeType& r) : m_children(r.m_children.clone()) { } CompositeType::CompositeType() { } CompositeType::~CompositeType() { } void CompositeType::clearAllCompositeChildren() { m_children.erase(m_children.begin(),m_children.end()); } void CompositeType::addComposition(const Name_t& name,Type* tp) { m_children[name]=tp; // <========= THIS LINE IS THE PROBLEM } void CompositeType::delComposition(const Name_t& name) { m_children.erase(name); } I can't get the program to compile because gcc keeps complaining m_children[name] don't has operator= and that type is an abstract class and can't be initialized. I read all the boost::prt_container documentation and I couldn't find what I'm doing wrong. I also tried m_children.insert(name,tp); to no avail. I'll greatly appreciate any help. Thanks, Gustavo
participants (1)
-
Gustavo Ribeiro Alves