未定义模板'std::basic_string, std::分配器 >'的隐式实例化

时间:2022-12-01 09:43:24

In the project I have been working on, we have to send Cocoa notifications from C++ sub-projects to the main project above it. To do this we construct a map to act as a key-value store for the userInfo dictionary of the notification.

在我一直在做的项目中,我们必须将来自c++子项目的Cocoa通知发送到上面的主项目。为此,我们构造一个映射作为通知的userInfo字典的键值存储。

In one of the projects, the following code compiles just fine:

在其中一个项目中,以下代码编译得很好:

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);

However, when this is copied into an identical file in another sub-project, the compiler throws the following on the userInfo->insert calls:

但是,当在另一个子项目中复制到一个相同的文件时,编译器会在userInfo->插入调用中抛出以下命令:

"Implicit instantiation of undefined template 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >'" 

..and it cannot find the function for PostCocoaNotification:

. .也找不到后茧化的功能:

No matching function for call to 'PostCocoaNotification'

Additionally, it throws the following errors in system headers:

此外,它在系统标题中还会抛出以下错误:

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

I've no idea what I've done to cause such chaos, especially when the code runs perfectly fine in another sub-project (successfully sending notifications). Any insight to the problem would be very welcome.

我不知道我做了什么导致这样的混乱,特别是当代码在另一个子项目中完美运行(成功发送通知)。对这个问题的任何见解都将受到欢迎。

1 个解决方案

#1


59  

You need to include these headers:

你需要包括这些标题:

#include <string>
#include <sstream>
#include <iostream>

#1


59  

You need to include these headers:

你需要包括这些标题:

#include <string>
#include <sstream>
#include <iostream>