你将如何专门化std::great

how would you specialize std::greater

本文关键字:std great 专门化      更新时间:2023-10-16

std::list<MyBaseClass*> objects;

如何(指语法)专门化std::great对于std::list 的排序方法

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

产生错误:

C2662:"int MyBaseClass::get_index(void)":无法将"this"指针从"const MyBaseClass"转换为"MyBaseClass&"转换丢失限定符

你能给我解释一下这个问题吗?

eidos::MyBaseClass::get_index()的实现需要标记为"const"。