我无法清除地图内存(我通过Valgrind检查).
#include <map>
class testMap {
public:
testMap(){}
~testMap();
void insert_map(int, int);
private:
std::map<int,int> _map;
};
void testMap::insert_map(int i, int j){
_map.insert( pair<int, int>(i,j));
}
Run Code Online (Sandbox Code Playgroud)
我试过_map.clear(),手动erase()删除_map->second但不是没有运气.
感谢所有回复.实际上map一个人不是问题,但是map单身人士会导致泄密.下面的代码有什么问题?
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include "Object.h"
#include<boost/smart_ptr.hpp>
using namespace std;
class Singleton {
public:
// A wrapper around Object class
class object
{
public:
object() : _object(new Object())
{}
Object get(void)
{ return _object.get(); }
private:
boost::shared_ptr<Object> …Run Code Online (Sandbox Code Playgroud)