简体   繁体   English

您如何专门研究std :: greater

[英]how would you specialize std::greater

have a 有一个

std::list<MyBaseClass*> objects;

how ( mean a syntax) would you specialize std::greater for the sort method of std::list 您如何(意味着语法)将std :: greater专门用于std :: list的排序方法

template<> class std::greater<MyBaseClass*> {
public:
     bool operator()(const MyBaseClass*& lhs, const MyBaseClass*& rhs) const
     {
         return lhs->get_index() > rhs->get_index();
     }

produces the error: 产生错误:

C2662: 'int MyBaseClass::get_index(void)' : cannot convert 'this' pointer from 'const MyBaseClass' to 'MyBaseClass &' Conversion loses qualifiers C2662:'int MyBaseClass :: get_index(void)':无法将'this'指针从'const MyBaseClass'转换为'MyBaseClass&'转换丢失了限定符

can you explain me the problem please? 你能给我解释一下这个问题吗?

您的eidos::MyBaseClass::get_index()需要标记为“ const”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM