Xref: utzoo comp.object:528 comp.lang.c++:5709 Path: utzoo!utgpu!watserv1!watmath!watmsg!gjditchfield From: gjditchfield@watmsg.waterloo.edu (Glen Ditchfield) Newsgroups: comp.object,comp.lang.c++ Subject: Re: Dumb question Message-ID: <32106@watmath.waterloo.edu> Date: 29 Nov 89 16:24:27 GMT References: <61737@aerospace.AERO.ORG> <9938@june.cs.washington.edu> <2122@tukki.jyu.fi> <2159@tukki.jyu.fi> <9191@microsoft.UUCP> Sender: daemon@watmath.waterloo.edu Reply-To: gjditchfield@watmsg.waterloo.edu (Glen Ditchfield) Organization: U. of Waterloo, Ontario Lines: 23 In article <9191@microsoft.UUCP> jimad@microsoft.UUCP (Jim Adcock) writes: >// in any case -- here's a quick and dirty example of what I think >// people have been talking about.... [Code that sketches a sortable list omitted.] Note that the list's sort() function used the `<' function defined by the list element class, which in turn used a virtual compare() function. I think some people were talking about this, but other people wrote about a scheme where the compare() function is a virtual function of the list class. I like putting compare() in the list class better. You can have different lists that sort the same element type in different ways; invoices sorted by customer in one list, and by date in another. The sort routine isn't bound to one element class function name, like `<'. You can sort by things like string length, which wouldn't normally be done with `<'. In practice, in C++, wouldn't it be simpler to pass a comparison function as an argument to the sort() function? If the list's elements are always sorted in the same order, the list insertion operation would insert elements in that order in the first place. Glen Ditchfield gjditchfield@violet.uwaterloo.ca Office: DC 2517 Dept. of Computer Science, U of Waterloo, Waterloo, Ontario, Canada, N2L 3G1 Gorbachev is a CIA mole. Brought to you by Super Global Mega Corp .com