C++优先级队列向量/列表?

发布于 2024-09-14 15:09:43 字数 184 浏览 1 评论 0 原文

为什么 C++ 不允许这样的事情呢?

我需要有多个优先级队列,其数量将在运行时确定。

这无法编译

std::vector>

有更好的方法吗?

Why wouldn't C++ allow something like that ?

I need to have multiple priority queues, the number of which would be determined at run time.

This fails to compile

std::vector<std::priorityqueue<Class A>>.

Is there a better approach ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

生寂 2024-09-21 15:09:43

正确的代码是:

std::vector<std::priority_queue<A> >

注意Class不属于A旁边,priority_queue里面有一个下划线,并且需要一个空格位于两个直角括号之间(>> 被解析为右移运算符)。

这还要求 A 小于可比较(如果不是,则必须提供优先级队列使用的比较函数)。

The correct code would be:

std::vector<std::priority_queue<A> >

Note that Class does not belong next to A, priority_queue has an underscore in it, and there is a space required between the two right angle brackets (>> is parsed as a right shift operator).

This also requires that A is less-than comparable (if it is not, then you must provide a comparison function to be used by the priority queue).

柠檬心 2024-09-21 15:09:43

这应该可以正常工作。只是语法应该是:(

std::vector<std::priority_queue<A> >

注意末尾附近的空格(“”)。

This should work just fine. Just the syntax should be:

std::vector<std::priority_queue<A> >

(note the space (" ") near the end.

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