出於某種原因,我不能將值插入到靜態地圖容器中。我使用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