无法在 xcode ios 项目中声明 C++ 向量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9673739/
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-14 23:37:05  来源:igfitidea点击:

Can't declare C++ vector in xcode ios project

c++iosxcodevectorstd

提问by Luchian Grigore

I'm trying to use a vector in a C++ class with xcode but it's giving me errors. The file has the .mmextension that is required for C++ files.

我试图在带有 xcode 的 C++ 类中使用向量,但它给了我错误。该文件具有.mmC++ 文件所需的扩展名。

This is my code:

这是我的代码:

class Synth{

private:

    int bpm;
    std::vector<Note> notesList;

public:

};

It's giving me these two errors:

它给了我这两个错误:

  • error: Semantic Issue: Use of undeclared identifier 'std'
  • error: Parse Issue: Expected member name or ';' after declaration specifiers
  • 错误:语义问题:使用未声明的标识符“std”
  • 错误:解析问题:预期的成员名称或“;” 声明说明符后

I also tried with using namespace std;on top but that made no difference. Any ideas what could be causing this?

我也试过using namespace std;在上面,但这没有什么区别。任何想法可能导致这种情况?

回答by Luchian Grigore

Yes, you need to include the header:

是的,您需要包含标题:

 #include <vector>

Don't use using namespace stdin a header file, rather keep your code as it is, with the explicit qualifier: std::vector.

不要using namespace std在头文件中使用,而是使用显式限定符保持代码原样:std::vector