好的,所以我有一個函數,它接受一個字符串並以特定方式將其轉換爲矢量。該代碼是:更改矢量時發生幾乎不可讀的錯誤
std::vector<std::string> delimit_string(std::string s, std::string delimiter) {
std::vector<std::string> outVector;
size_t pos = 0;
std::string token;
while ((pos = s.find(delimiter)) != std::string::npos) { //thx http://stackoverflow.com/questions/14265581/parse-split-a-string-in-c-using-string-delimiter-standard-c
token = s.substr(0, pos);
outVector.push_back(token);
s.erase(0, pos + delimiter.length());
}
return outVector;
}
std::vector<std::string> parse_map(std::string map, SDL_Renderer* ren) {
std::vector<std::string> mapString = delimit_string(map, "^");
for (int i = 0; i < mapString.size(); ++i) {
size_t pos;
while ((pos = mapString[i].find("|")) != std::string::npos){ //search for a string "|" or exit if it isnt found
mapString[i].erase(pos, pos);
std::string string1 = mapString[i].substr(0, pos); //from pos to beginning
std::string string2 = mapString[i].substr(pos + 1, std::string::npos); //from pos+1 to end
mapString.erase(mapString.begin() + i);
mapString.insert(mapString.begin() + i, string2);
mapString.insert(mapString.begin() + i, "|");
mapString.insert(mapString.begin() + i, string1);
}
}
//now mapstring looks somewhat like this:
//[commoner.bmp, commoner.bmp, |, commoner.bmp, commoner.bmp]
return mapString;
}
如果我通過它像"hello.bmp^hello.bmp|hello.bmp"
的東西,它應該返回,看起來有點像["hello.bmp", "hello.bmp", "|", "hello.bmp"]
雖然是矢量,而不是返回這一點,在編譯時使用此功能錯誤(而不可讀)錯誤:
Error 1 error LNK2019: unresolved external symbol "class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > __cdecl parse_map(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" ([email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z) referenced in function _SDL_main C:\Users\spng453\documents\visual studio 2013\Projects\loot\loot\main.obj loot
我知道,通過排除法,即parse_map
函數是在編譯時導致錯誤的功能,它很可能是由於我不千牛由於媒介如何運作。任何幫助將
大概在函數原型和功能不匹配的執行參數列表;仔細檢查它們。 –
非常感謝。函數原型只是'std :: string map',不包含渲染器。這是我做過的最愚蠢的錯誤。 – Aearnus