list的编译器错误
我正在尝试按照此处的示例创建一个字符串列表。下面给出了语法错误:
private: list<string> images;
错误(全部在上面声明所在的行上):
syntax error : missing ';' before '<'
missing type specifier - int assumed. Note: C++ does not support default-int
unexpected token(s) preceding ';'
它位于一个类中,除了它之外只有一个构造函数,并且没有它它也可以正常编译。我做错了什么?
I'm trying to create a list of strings, following the example here. This below gives me syntax errors:
private: list<string> images;
The errors (all on the line where the above declaration is):
syntax error : missing ';' before '<'
missing type specifier - int assumed. Note: C++ does not support default-int
unexpected token(s) preceding ';'
It's in a class with only a single constructor besides it, and it compiles fine without it. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否同时
#include
了
和
? 从namespace std
导入名称list
和string
另外,您是否通过编写或
您收到的错误与名称不一致易于访问,所以这是我最好的猜测。
编辑:由于这是在头文件中,因此您不应该使用上述任何一种结构(感谢 wilhelmtell 指出这是一个头文件!)。相反,您应该将名称完全限定为
这样,编译器确切地知道在哪里查找
list
和string
。Did you
#include
both<list>
and<string>
? Also, did you import the nameslist
andstring
fromnamespace std
by writing eitheror
The error you're getting is consistent with the names not being accessible, so this is my best guess.
EDIT: Since this is in a header file, you should not be using either of the above constructs (thanks to wilhelmtell for pointing out that this is a header file!). Instead, you should fully-qualify the names as
This way the compiler knows exactly where to look for
list
andstring
.您需要使用 命名空间。
键入
std::list
或在#include
和之后添加
指令。using namespace std;
>#include一个简单的工作程序:
You need to qualify the
list
andstring
types with their namespace.Either type
std::list<std::string>
or addusing namespace std;
after the#include <string>
and#include <list>
directives.A simple working program: