【发布时间】:2020-10-13 12:53:37
【问题描述】:
我正在查看一些 STL 文档。我看到按降序存储的优先级队列的语法是:
std::priority_queue<int> q ;
//gives 9 8 7 6 5 4 3 2 1 when pushed and obtained
但是,对于以升序方式存储,它是:
std::priority_queue< int, std::vector<int>, std::greater<int> > q ;
//gives 1 2 3 4 5 6 7 8 9 when pushed and obtained
我想知道第二个例子中额外模板参数的具体用途是什么。例如,std::vector<int> 在该示例中做了什么?
另外,有人可以进一步解释这个声明吗?
priority_queue< pair<int ,int > , vector< pair<int ,int > > , greater< pair<int ,int > > > q ;
【问题讨论】:
-
在 C++ 中,如果不设置前面的参数,则无法设置第三个参数。
标签: c++ c++11 vector stl priority-queue