你会如何专门的std ::更大

问题描述:

你会如何专门的std ::更大

std::list<MyBaseClass*> objects; 

如何(指的是语法),你会特化std ::更大 性病的排序方法::列表

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)' : cannot convert 'this' pointer from 'const MyBaseClass' to 'MyBaseClass &' Conversion loses qualifiers

你能解释一下我的问题吗?

+1

你为什么要专注'std :: greater'?实现'operator>'而不是你的类或指向你的类的指针。你看到的错误是因为'get_index'不是'const'成员函数。 – Praetorian 2015-03-02 05:44:28

+0

你是对的,运营商>会更喜欢。 我会尽力走这条路。无论如何,感谢你的“const”它当然也适用 – amigo421 2015-03-02 07:35:21

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