27
在我一直在研究的項目中,我們必須將Cocoa通知從C++子項目發送到它的主要項目。爲此,我們構造一個映射,以充當通知的userInfo字典的鍵值存儲區。未定義模板的隱式實例化std :: basic_string <char,std :: char_traits <char>,std :: allocator <char>>'
在項目之一,下面的代碼編譯就好:
std::map<std::string, std::string> *userInfo = new std::map<std::string, std::string>;
char buffer[255];
sprintf(buffer, "%i", intValue1);
userInfo->insert(std::pair<std::string, std::string>("intValue1", std::string(buffer)));
sprintf(buffer, "%i", intValue2);
userInfo->insert(std::pair<std::string, std::string>("intValue2", std::string(buffer)));
if(condition)
userInfo->insert(std::pair<std::string, std::string>("conditionalValue", "true"));
PostCocoaNotification("notificationName", *userInfo);
然而,當該被複制到另一個子項目相同的文件時,編譯器會引發對userInfo-以下>插入電話:
"Implicit instantiation of undefined template 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >'"
..和它找不到功能PostCocoaNotification:
No matching function for call to 'PostCocoaNotification'
此外,它拋出系統頭以下錯誤:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/usr/include/c++/4.2.1/bits/stl_pair.h:73:11: Implicit instantiation of undefined template 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >'
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/usr/include/c++/4.2.1/bits/stl_pair.h:74:11: Implicit instantiation of undefined template 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >'
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/usr/include/c++/4.2.1/bits/stl_pair.h:73:11: Implicit instantiation of undefined template 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >'
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/usr/include/c++/4.2.1/bits/stl_tree.h:1324:13: Cannot initialize a parameter of type '_Link_type' (aka '_Rb_tree_node<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > *') with an rvalue of type '_Const_Link_type' (aka 'const _Rb_tree_node<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > *')
我不知道我做了什麼造成這種混亂,尤其是當代碼運行在另一個子項目完美的罰款(發送成功通知)。對這個問題的任何洞察力都將非常受歡迎。
我的第一個猜測是,你需要包括的東西。可能是對(實用程序)或字符串的標頭。 – Kindread
我也猜'串' – doctorlove
我不認爲字符串頭是罪魁禍首,userInfo被初始化的行('std :: map * telemetry = new std: :map ;')不會引發任何錯誤。 –
Andrew