[英]make_heap() compilation issue
编译如下:
class Compare
{
bool cmp(const int& a, const int& b){return a>b;}
};
int main()
{
vector<int, Compare> v;
make_heap(v.begin(), v.end(), Compare());
}
导致编译错误-在“类比较”中没有名为“ rebind”的类模板。 可能是什么原因? 我将RedHat Linux与gcc一起使用。 非常感谢。
您在begin()和end()附近缺少括号,并且以错误的方式定义比较器。 它可能看起来像这样:
#include <vector>
#include <algorithm>
#include <functional>
struct Compare: std::binary_function<int const&, int const&, bool>
{
public:
bool operator()(const int& a, const int& b){return a>b;}
};
int main()
{
std::vector<int> v;
std::make_heap(v.begin(), v.end(), Compare());
return 0;
}
std :: vector <>没有比较器模板参数; 它的第二个参数有一个分配器 。
您正在将比较器用作矢量模板参数列表中的分配器。
class Compare
{
public:
bool operator()(const int& a, const int& b){return a>b;}
};
int main()
{
vector<int> v;
make_heap(v.begin(), v.end(), Compare());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.