2013-10-07 17 views
27

परियोजना में मैं पर काम कर रहा है, हम करने के लिए सी ++ उप-परियोजनाओं से कोको सूचना भेजने के लिए है इसके ऊपर मुख्य परियोजना। ऐसा करने के लिए हम अधिसूचना के userInfo शब्दकोश के लिए एक कुंजी-मूल्य स्टोर के रूप में कार्य करने के लिए एक मानचित्र बनाते हैं।अंतर्निहित इन्स्टेन्शियशन 'std :: basic_string <चार, std :: char_traits <char>, std :: संभाजक <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' 
,210

इसके अतिरिक्त, यह प्रणाली हेडर में निम्न त्रुटियों को फेंकता है:

/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> > > > *') 

मुझे नहीं पता कि मैं विशेष रूप से जब कोड एक और उप-परियोजना में बिल्कुल ठीक चलाता है इस तरह अराजकता पैदा करने के लिए, क्या किया है (सफलतापूर्वक भेजने गए अधिसूचना)। समस्या का कोई अंतर्दृष्टि बहुत स्वागत है।

+1

मेरा पहला अनुमान है कि आप कुछ शामिल करने की ज़रूरत है। शायद जोड़ी (उपयोगिता) या स्ट्रिंग के लिए हेडर। – Kindread

+0

मुझे लगता है कि 'स्ट्रिंग' भी – doctorlove

+0

मुझे नहीं लगता कि स्ट्रिंग हेडर अपराधी है, वह लाइन जहां userInfo प्रारंभ किया गया है ('std :: map * telemetry = new std: : नक्शा ; ') कोई त्रुटि नहीं फेंकता है। – Andrew

उत्तर

50

आप इन शीर्ष लेख शामिल करने की जरूरत है:

#include <string> 
#include <sstream> 
#include <iostream> 
संबंधित मुद्दे