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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 10:34:52  来源:igfitidea点击:

Xcode C++ Vectors: Implicit instantiation of undefined template

c++xcodevectorheaderimplicit

提问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 中;

回答by Quentin

From the comments:

来自评论:

The stdnamespace houses both of those templates. Change vectorto std::vector, and stringto std::string. – WhozCraig

std命名空间安置这两方面的模板。更改vectorstd::vector,并更改stringstd::string。– WhozCraig