Check out Fruny''s link to STLPort for a well-implemented standard library. Once you go STLPort, you''ll never go back :D
It''s a bit tricky to get started using, because if you plan on using their IO streams you have to build the proper library first. However, if you just plan on making use of everything else, you have to tell the library that you don''t plan on using thier IO streams by defining a certain thing... the reference should tell you exactly what you define.
Sorting a std::list<cClassName*>
The predicate for list::sort is the functor "greater".
greater is defined as:
where, operator() returns true if x > y.
As you can see, the list::sort function, since it is storing pointers, will pass references to the *pointer values* to the greater predicate (i.e., greater<cRenderableObject *>
Therefore, you need to inherit a specialized greater predicate to handle pointers, like this:
Add an operator> to your cRenderableObject class, then, pass that predicate to the sort function and everything should be okay.
[edited by - fizban75 on March 3, 2003 12:56:43 PM]
[edited by - fizban75 on March 3, 2003 12:58:50 PM]
greater is defined as:
template<class T>struct greater : public binary_function<T, T, bool> {bool operator()(const T& x, const T& y);};
where, operator() returns true if x > y.
As you can see, the list::sort function, since it is storing pointers, will pass references to the *pointer values* to the greater predicate (i.e., greater<cRenderableObject *>
Therefore, you need to inherit a specialized greater predicate to handle pointers, like this:
template<T>struct pointer_greater : public greater<T> { bool operator()(const T& x, const T& y) { return *x > *y; }};
Add an operator> to your cRenderableObject class, then, pass that predicate to the sort function and everything should be okay.
[edited by - fizban75 on March 3, 2003 12:56:43 PM]
[edited by - fizban75 on March 3, 2003 12:58:50 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement