使用STL的列表对象

发布于 2024-08-23 01:25:36 字数 489 浏览 2 评论 0原文

我想用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自由如风 2024-08-30 01:25:36

queue 也是一个模板类,因此您需要指定队列中包含的元素类型。另外,-在C++中不是合法的标识符字符;也许你的意思是_

std::list<std::queue<SOME_TYPE_HERE> > list_queue;

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 _?

std::list<std::queue<SOME_TYPE_HERE> > list_queue;
2024-08-30 01:25:36

还有“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文