Vincenzo Cappello wrote:
I need a map that contain different object of the same base class like:
std::map< int, base_class* >
someone tell me is no correct using pointer in containers so i change to:
std::map< int, std::auto_ptr< base_class > >
someone tell me is no correct using auto_ptr in containers...
someone can tell me the right way?
Use a smart pointer that has value semantics for comparison operator.
The boost shared_ptr doesn't have value semantics, and IMHO, it's not
the right smart pointer for this task.
The following smart pointers do have value semantics, and moreover have
automatic cloning.
http://code.axter.com/cow_ptr.h http://code.axter.com/copy_ptr.h http://code.axter.com/smart_ptr.h
Example:
std::map< int, cow_ptr< base_class > >
Check out the following link for partial help documents on usage:
http://axter.com/smart_ptr