草庐IT

c++ - 正确使用 std::map 作为类成员

过去我总是创建这样的map:classTestClass{private:std::map*mapA;};TestClass::TestClass{mapA=newstd::map();}TestClass::~TestClass{mapA->clear();//notnecessarydeletemapA;}所以,现在我在Stackoverflow上到处阅读:尽可能避免指针目前我想创建没有指针和new的映射(不需要自己删除对象,并且内存泄漏的危险较小)!classTestClass{public:TestClass():mapA()//thisisalsoneeded?{};priv