ptr_map and pointer
问题 I'm using ptr_map from boost for storing objects derived from some base abstract type. class Entity { virtual void foo() = 0; }; class Entity1 : public Entity {}; class Entity2 : public Entity {}; boost::ptr_map<string, Entity> someMap; // We could store pointers for abstract type Inserting works great: someMap.insert("someKey", new Entity1()); someMap.insert("someKey", new Entity2()); But not returning from map: template<typename EntityType> EntityType *GetEntity(const string &entityName) {