0
所以我有一個構造函數,看起來像 HNS :: HNS vector >> storage(1000,vector>(1000));訪問嵌套的STL結構和大小調用
我也有一個函數來插入元素,看起來像
void HNS::insert(const string& host, const int& ip) {
hash<HostName> hash;
auto resultno = hash(host);
auto result = resultno%size;
cout << "size of current container is : " << (storage.at(result)).size() << endl;
storage.at(result).emplace_back(host, ip);
}
但是,在運行時,它的emplace_back和cout電話給我超出範圍異常。 在構造函數中,我可以打印storage.at(600).size(),但在插入函數中,cout和emplace調用失敗。任何想法爲什麼這是?
問候
*編譯時,emplace_back函數在運行時會給我一個超出範圍的異常*什麼? – Borgleader 2015-02-23 19:59:56
我認爲這是因爲我沒有正確定義存儲。它需要是全球性的。我如何去做這件事? – enrm 2015-02-23 20:04:02
@enrm'resultno%size''size'在你發佈的代碼中來自哪裏? – PaulMcKenzie 2015-02-23 20:05:30