Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: C++
Expertise: Beginner
Jul 18, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

VC++ 5.0 and STL predicates

How can I provide my own predicate for the list::sort method in Visual C++ 5.0? The method appears to require that any function object passed must be derived from greater but in stepping through the code in the debugger, I noticed that my function object is cast to a base class (std::binary_function) that has a non-virtual operator() method so my operator() never gets called. Am I missing something?

There is no such restriction for the comparison algorithm for sort in STL. As a matter of fact, there is not a single place where STL relies on virtual functions. If your compiler's implementation casts the comparator to the base class' version, that is a serious bug in the implementation.

Here is the definition of list::sort as per the draft standards:

template  >
class list
 // other stuff

 template  void sort (Compare comp)
Here the only restriction on the Compare type is that it must have a publically visible function call operator [operator ()()].
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date