无法在 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
Can't declare C++ vector in xcode ios project
提问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 .mm
extension that is required for C++ files.
我试图在带有 xcode 的 C++ 类中使用向量,但它给了我错误。该文件具有.mm
C++ 文件所需的扩展名。
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 std
in a header file, rather keep your code as it is, with the explicit qualifier: std::vector
.
不要using namespace std
在头文件中使用,而是使用显式限定符保持代码原样:std::vector
。