I am trying to compile the following piece of code with the Studio 7 CC compiler. When I compile the code I get the following error:
foo.cpp, line 42: Error: Could not find a match for std::list<foo*, std::allocator<foo*>>::sort(std::greater<foo*>).
Any help would be appreciated
#include <list>
#include <iostream>
#include <functional>
struct foo
{
int nValue;
foo(int n=0) : nValue(n){ }
};
typedef std::list<foo *> pFooList;
template <>
struct std::greater<foo*>
{
bool operator()(const foo* lhs, const foo* rhs) const
{
return lhs->nValue < rhs->nValue;
}
};
using namespace std;
int main()
{
pFooList FL;
pFooList::iterator it;
FL.push_back(new foo(1));
FL.push_back(new foo(3));
FL.push_back(new foo(2));
it = FL.begin();
while ( it != FL.end())
{
cout << (*it)->nValue << endl;
++it;
}
cout << endl;
FL.sort(std::greater<foo*>());
it = FL.begin();
while ( it != FL.end())
{
cout << (*it)->nValue << endl;
++it;
}
cout << endl;
}