莫非hash_map不允许使用带临界区的对象么?还是一旦初始化了临界区的对象就不允许复制了??
#include "stdafx.h"
#include <windows.h>
#include <hash_map>
#include <string>using namespace std;
using namespace stdext;class CTest
{
public:
CTest()
{
memset(&m_sec, 0, sizeof(CRITICAL_SECTION));
InitializeCriticalSection(&m_sec);
}
virtual ~CTest()
{
DeleteCriticalSection(&m_sec);
}protected:
CRITICAL_SECTION m_sec;
};int _tmain(int argc, _TCHAR* argv[])
{ hash_map<std::string,CTest> m_test;
CTest objPingTest; m_test["test"] = objPingTest;
return 0;
}
#include "stdafx.h"
#include <windows.h>
#include <hash_map>
#include <string>using namespace std;
using namespace stdext;class CTest
{
public:
CTest()
{
memset(&m_sec, 0, sizeof(CRITICAL_SECTION));
InitializeCriticalSection(&m_sec);
}
virtual ~CTest()
{
DeleteCriticalSection(&m_sec);
}protected:
CRITICAL_SECTION m_sec;
};int _tmain(int argc, _TCHAR* argv[])
{ hash_map<std::string,CTest> m_test;
CTest objPingTest; m_test["test"] = objPingTest;
return 0;
}
解决方案 »
- 关闭程序后出现应用程序错误
- CListCtrl
- 怎么做一个程序,让它运行在win2000的服务里??????
- 如何定义一个类的“私有常量”?
- 在视图中用CDC类的函数画的图形如何保留驻
- 用EnumProcessModules的到和Modules有关的,用EnumProcesses得到Process有关的,请问Modules和Process之间的关系,区别?
- 我做了一个对话框,加入了picture control,然后希望显示我的一张bitmap,如何做?(在先给分,分不够再加!)
- SMTP用协议可以传输附件是声音文件的邮件吗?下面的MSDN说的uuencode是什么格式?
- 散分大讨论:在外企中的程序员(日,美,欧)
- 已知钩子句柄的情况下,如何分析出钩子的类型
- 无窗口htmlview
- 弱问模态对话框弹出后对主线程的影响具体有哪些方面?
这一行,hasp_map不仅仅产生了一个CTest对象,它可能产生好几个临时对象。换句话说可能会多次构造后,再多次析构。
还有你最好写个copy构造函数,避免m_sec的直接复制。