【发布时间】:2015-05-28 03:47:14
【问题描述】:
我的编译器拒绝编译这个简单的代码:
struct mystruct{
int x;
bool operator<(const mystruct& y) const{ return x < y.x; }
};
std::map<mystruct, int> test;
auto it = std::lower_bound(test.begin(), test.end(), mystruct{2});
我收到了错误
error C2893: Failed to specialize function template 'unknown-type std::less<void>::operator ()(_Ty1 &&,_Ty2 &&) const'
查看this 链接,您似乎只需要定义一个常量比较运算符,这正是我正在做的。我在这里有什么遗漏吗?
【问题讨论】:
标签: c++ operator-overloading stl-algorithm