[英]Can't use std::greater where std::less is used
這段代碼編譯得很好:
#include <queue>
#include <functional>
std::priority_queue<int> q (std::less<int>{});
而這段代碼給出了奇怪的編譯錯誤
#include <queue>
#include <functional>
std::priority_queue<int> q (std::greater<int>{});
std::priority_queue
的第三個模板參數默認為std::less
。 因此,您正在調用的構造函數需要一個std::less
object。 您必須更改第三個模板參數:
std::priority_queue<int, std::vector<T>, std::greater<int>> q (std::greater<int>{});
也不需要傳入std::greater<int>{}
,因為有一個默認構造函數可以為您處理。
std::priority_queue<int, std::vector<T>, std::greater<int>> q;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.