首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >未定义模板'std::basic_string<char,std::char_traits<char>,std::allocator<char> >‘的隐式实例化

未定义模板'std::basic_string<char,std::char_traits<char>,std::allocator<char> >‘的隐式实例化
EN

Stack Overflow用户
提问于 2013-10-07 19:13:13
回答 2查看 78.1K关注 0票数 60

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

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

代码语言:javascript
运行
复制
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->insert调用中抛出以下代码:

代码语言:javascript
运行
复制
"Implicit instantiation of undefined template 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >'" 

..and它找不到PostCocoaNotification的函数:

代码语言:javascript
运行
复制
No matching function for call to 'PostCocoaNotification'

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

代码语言:javascript
运行
复制
/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> > > > *')

我不知道我做了什么才会造成这样的混乱,特别是当代码在另一个子项目中运行得很好时(成功地发送通知)。对这个问题的任何见解都将是非常受欢迎的。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-11-07 20:51:23

您需要包括此标头:

代码语言:javascript
运行
复制
#include <string>
票数 128
EN

Stack Overflow用户

发布于 2021-10-08 16:31:35

尝试在标题下面添加,

#include <sstream>

https://www.cplusplus.com/reference/sstream/stringstream/stringstream/

票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19223360

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档