使用STL的列表对象
我想用 C++ 创建一个队列列表,但编译器给了我一些神秘的消息:
#include <list>
#include <queue>
class Test
{
[...]
list<queue> list_queue;
[...]
}
输出:
error C2143: syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2238: unexpected token(s) preceding ';'
即使我使用 int 作为模板参数,它也会给我同样的错误。这是怎么回事?
(顺便说一句,我使用的是 VC++ 2008 EE)
I want to create a list of queues in C++ but the compiler gives me some cryptic messages:
#include <list>
#include <queue>
class Test
{
[...]
list<queue> list_queue;
[...]
}
Output:
error C2143: syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2238: unexpected token(s) preceding ';'
It gives me the same error even if I use int as the template paramenter. What's going on?
(btw, I'm using VC++ 2008 EE)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
queue
也是一个模板类,因此您需要指定队列中包含的元素类型。另外,-
在C++中不是合法的标识符字符;也许你的意思是_
?queue
is a template class as well, so you'll need to specify the element type contained in your queues. Also,-
is not a legal identifier character in C++; perhaps you meant_
?还有“using namespace std”,并且在类定义 280Z28 之后需要有一个分号,
这对于生产代码来说在头文件中“using”是一个坏主意。不过,这仍然是一个合理的故障排除步骤,可以快速查看主要问题是否是标识符搜索范围。
also "using namespace std", and there needs to be a semicolon after your class definition
280Z28 is right that "using" in a header file is a bad idea for production code. It's still a reasonable troubleshooting step though, to quickly see if the primary problem is identifier search scope.