Dear all,
I'm having an issue using auto_ptr inside a container. I have a std::map with the following format:
These MediatorEvent classes are shared among a lot of clients through a Facade,Code:typedef map<date, const MediatorEvent *> AtributeMap; // date is boost::gregorian typedef pair<date, const MediatorEvent *> AtributePair; typedef AtributeMap::iterator iAtributeMap; typedef AtributeMap::reverse_iterator rAtributeMap;
that's why it's declared as "const".
However, I would like to refer methods of this object, which is not possible since the g++ do not allow the reference to be a left parameter
If I remove the "const" on the container it works fine, but it allows any client to explicit delete the object, and this will bring a lot of inconsistencies in the code.Code:MediaorEvent *m = _facade->getEvent(...); m->c_scr(); // main.cpp:81: error: passing 'const MediatorEvent' as 'this' argument of 'const std::string MediatorEvent::c_str()' discards qualifiers
Another possibilty to avoid this is to use auto_ptr, but I'm not sure how and neither where to use it.
My question to you guys is: Is it possible to use it safetly inside a container, such as:
??Code:typedef map<date, auto_ptr<MediatorEvent> > AtributeMap; typedef pair<date, auto_ptr<MediatorEvent> > AtributePair; typedef AtributeMap::iterator iAtributeMap; typedef AtributeMap::reverse_iterator rAtributeMap;
My concern is to assure that the customers would share the object pointer but none of them would change the object or delete it. I tried to use a flyweight and even the Factory design pattern, but all of them introduces a lot of complexity in the architecture and in the code and I'm trying to avoid introducing new patterns for now.
Any suggestions or ideas?
Thanks & regards,
yezaim



LinkBack URL
About LinkBacks





kkk