- 论坛徽章:
- 0
|
各位大侠帮我看下吧
编译显示如下:
"test.cpp", line 56: Error: Could not find a match for std::list<Element, std::allocator<Element>>::sort(CompA).
"test.cpp", line 57: Error: Could not find a match for std::list<Element, std::allocator<Element>>::sort(CompB).
编译环境是CC,Forte C++ 6 update 2
代码如下:
#include <list>
using namespace std;
class Element
{
public:
Element(int x, int y) : a(x), b(y)
{
}
~Element() {}
getA() const
{
return a;
}
getB() const
{
return b;
}
private:
int a;
int b;
};
class CompA
{
public:
operator()(const Element& x, const Element& y)
{
return (x.getA() < y.getA());
}
};
class CompB
{
public:
operator()(const Element& x, const Element& y)
{
return (x.getB() < y.getB());
}
};
int main()
{
list<Element> listE;
Element obj1(1,2);
Element obj2(2,1);
listE.push_back(obj1);
listE.push_back(obj2);
listE.sort(CompA());
listE.sort(CompB());
listE.clear();
return 0;
} |
|