Xcode C++ Vectors:未定义模板的隐式实例化
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49246160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode C++ Vectors: Implicit instantiation of undefined template
提问by Nathan Hale
I ran this code on a different IDE and it was successful. For some reason I get the above error message on Xcode. I assume I'm missing a header of some kind, but I'm not sure which one.
我在不同的 IDE 上运行了这段代码,它成功了。出于某种原因,我在 Xcode 上收到了上述错误消息。我想我错过了某种标题,但我不确定是哪一个。
#include <iostream>
#include <limits>
#include <string>
#include <vector>
int main() {
vector<string> listRestaurants; //here is where the semantic error appears
return 0;
}
回答by Sauvik Dolui
Xcode 10.2.1 was showing me the error
Implicit instantiation of undefined template 'std::__1::vector<std::__1::basic_string<char>, std::__1::allocator<std::__1::basic_string<char> > >'
.
Xcode 10.2.1 向我展示了错误
Implicit instantiation of undefined template 'std::__1::vector<std::__1::basic_string<char>, std::__1::allocator<std::__1::basic_string<char> > >'
。
#include <iostream>
#include <vector>
int main(int argc, const char * argv[]) {
std::vector<std::string> listRestaurants;
....
return 0;
}
Fixed my issue.
修复了我的问题。
回答by RyanLi
the vector and string were placed in the namespace std using namespace std;
使用命名空间 std 将向量和字符串放置在命名空间 std 中;