Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with sdt::list

807575Nov 30 2004 — edited Nov 30 2004
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;
    
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 28 2004
Added on Nov 30 2004
2 comments
109 views