你会如何专攻 std::greater

how would you specialize std::greater

有一个

std::list<MyBaseClass*> objects;

你会如何专攻(意思是语法)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();
     }

产生错误:

C2662: 'int MyBaseClass::get_index(void)' : cannot convert 'this' pointer from 'const MyBaseClass' to 'MyBaseClass &' Conversion loses qualifiers

你能解释一下问题吗?

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