我正在尝试创建“std::priority_queue”类型的变量,如下所示:
struct
{
bool operator()(std::vector<int> v1, std::vector<int> v2){return (v1[2] + v1[3]) > (v2[2] + v2[3]);};
} queueCompare;
std::priority_queue< std::vector<int>, std::vector< std::vector<int> >, queueCompare > queue;
但是编译器给了我这个错误:
expected a type, got `queueCompare'
我不太明白这里出了什么问题。据我所知,这应该是正确的创建方式。
这是无效的结构定义。正确的结构定义不是
struct {...} name
而是 struct name {...}
struct queueCompare
{
bool operator()(const std::vector<int>& v1, const std::vector<int>& v2){
return (v1[2] + v1[3]) > (v2[2] + v2[3]);
};
};