出于某种原因,我不能将值插入到静态地图容器中。我使用VS2010,这里是我的代码在静态地图容器中拼命插入值
Header File
class MyClass
{
static std::map<std::string,std::string> config_map;
static void SomeMethod();
};
Cpp File
std::map<std::string,std::string> MyClass::config_map ;
void MyClass::SomeMethod()
{
...
config_map.insert(std::pair<std::string,std::string>("dssd","Sdd")); //ERROR
}
这是错误,我得到
Unhandled exception at 0x0130ca29 in Test.exe: 0xC0000005: Access violation reading location 0x00000004.
我也试过config_map["str"] = "something"
。看来我不能在其中插入任何东西。有什么建议么 ?
这个断点在土地的XTree
_Pairib _Linsert(_Nodeptr _Node, bool _Leftish)
{ // try to insert node at _Node, on left if _Leftish
const value_type& _Val = this->_Myval(_Node);
_Nodeptr _Trynode = _Root(); //Breakpoint lands here
_Nodeptr _Wherenode = this->_Myhead;
bool _Addleft = true; // add to left of head if tree empty
while (!this->_Isnil(_Trynode))
{ // look for leaf to insert before (_Addleft) or after
_Wherenode = _Trynode;
if (_Leftish)
_Addleft = !_DEBUG_LT_PRED(this->comp,
this->_Key(_Trynode),
this->_Kfn(_Val)); // favor left end
else
_Addleft = _DEBUG_LT_PRED(this->comp,
this->_Kfn(_Val),
this->_Key(_Trynode)); // favor right end
_Trynode = _Addleft ? this->_Left(_Trynode)
: this->_Right(_Trynode);
}
你怎么称呼你的SomeMethod()?你确定在'.insert'调用发生异常吗?异常文本显示有一些NULL指针被取消引用。它看起来大多像是其他地方的错误。 – Inspired 2013-05-11 20:28:41
我肯定确定它发生在插入,因为我正在逐句通过陈述 – MistyD 2013-05-11 20:33:11
Somemethod()被另一个静态方法调用 – MistyD 2013-05-11 20:34:19