Xref: utzoo comp.object:498 comp.lang.c++:5657 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!bloom-beacon!eru!luth!sunic!tut!tukki!sakkinen From: sakkinen@tukki.jyu.fi (Markku Sakkinen) Newsgroups: comp.object,comp.lang.c++ Subject: Re: Dumb question Message-ID: <2159@tukki.jyu.fi> Date: 27 Nov 89 12:04:38 GMT References: <61737@aerospace.AERO.ORG> <9938@june.cs.washington.edu> <2122@tukki.jyu.fi> Reply-To: sakkinen@jytko.jyu.fi (Markku Sakkinen) SAKKINEN@FINJYU.bitnet (alternative) Organization: University of Jyvaskyla, Finland Lines: 37 In article <9938@june.cs.washington.edu> ewan@june.cs.washington.edu (Ewan Tempero) writes: >In article <61737@aerospace.AERO.ORG> abbott@itro3.org (Russell J. Abbott) writes: >>More concretely, can one write a sort routine that will sort a list of >>any type (perhaps not yet even defined) that responds to "<"? I would >>assume that one could, but it wasn't clear to me from the C++ material >>that I have how to do it. >You don't. If you want to sort a list, you don't apply a "sort" operation >to the list, you ask the list to sort itself. Since the list is an object >(we are talking about object-oriented systems where everything is an >object, right?) it should know its own representation (including the >type of the objects in the list) and so its "sort" operation will know >what to do. If it doesn't have a "sort" operation then how can you possibly >sort it? If you want to pass it to a "sorting" routine then you are >not following the object-oriented paradigm. >[...] I think you didn't notice that the question pertained specifically to C++, where not by far everything is an object! The slogan comes from the Smalltalk community, but if you take a sharp look at Smalltalk-80, you will note that at least variables are _not_ objects! It is only a kind of very puristic OO dogma that no "free" functions or procedures should be allowed, but they should always be methods of some class (or object). Apparently you also misread the question as meaning 'the _list_ responds to "<"', while the purpose was 'the [element] type responds to "<"'. So the question can be understood as: "How do I write a sort operation (member function) for a general list class in C++?" Thus, it does not necessarily imply a deviation from the pure OO paradigm. See article <2122@tukki.jyu.fi> for one answer to the original question. Markku Sakkinen Department of Computer Science University of Jyvaskyla (a's with umlauts) Seminaarinkatu 15 SF-40100 Jyvaskyla (umlauts again) Finland Brought to you by Super Global Mega Corp .com