ChristianH
August 3rd, 1999, 06:32 AM
How to sort my list by m_id???
Thank you in advance for every answer.
#include <iostream>
#include <list>
using namespace std;
class C {
public:
int m_id;
C( int i) { m_id=i; }
};
void main()
{
list< C* > l;
l.push_back( new C(2));
l.push_back( new C(4));
l.push_back( new C(1));
l.sort(); // sorted by the pointer to C
list< C* >::iterator itr;
for( itr=l.begin(); itr!=l.end(); itr++)
cout << (*itr)->m_id;
}
I suppose I need something like but don't know it exactly:
bool operator>( const C* pc1, const C* pc2) {
return pc1->m_id > pc2->m_id;
}
Thank you in advance for every answer.
#include <iostream>
#include <list>
using namespace std;
class C {
public:
int m_id;
C( int i) { m_id=i; }
};
void main()
{
list< C* > l;
l.push_back( new C(2));
l.push_back( new C(4));
l.push_back( new C(1));
l.sort(); // sorted by the pointer to C
list< C* >::iterator itr;
for( itr=l.begin(); itr!=l.end(); itr++)
cout << (*itr)->m_id;
}
I suppose I need something like but don't know it exactly:
bool operator>( const C* pc1, const C* pc2) {
return pc1->m_id > pc2->m_id;
}