尝试插入到(c)中时,’operator <'不匹配?
发布时间:2020-12-16 03:37:44 所属栏目:百科 来源:网络整理
导读:我使用 gcc 4.3.3尝试编译以下代码: struct testStruct { int x; int y; bool operator(testStruct other) { return x other.x; } testStruct(int x_,int y_) { x = x_; y = y_; } }; int main() {multisettestStruct setti; setti.insert(testStruct(10,10
我使用
gcc 4.3.3尝试编译以下代码:
struct testStruct { int x; int y; bool operator<(testStruct &other) { return x < other.x; } testStruct(int x_,int y_) { x = x_; y = y_; } }; int main() { multiset<testStruct> setti; setti.insert(testStruct(10,10)); return 0; } 我得到这个错误: 解决方法
操作符必须是const并引用const引用:
bool operator<(const testStruct &other) const { return x < other.x; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |