Xref: utzoo comp.object:582 comp.lang.c++:5802 Path: utzoo!attcan!utgpu!watserv1!watdragon!gvcormack From: gvcormack@watdragon.waterloo.edu (Gordon V. Cormack) Newsgroups: comp.object,comp.lang.c++ Subject: Re: (Very) Dymanic Typing (Was: Dumb question) Message-ID: <19045@watdragon.waterloo.edu> Date: 6 Dec 89 14:44:04 GMT References: <61737@aerospace.AERO.ORG> <9938@june.cs.washington.edu> <1989Dec5.195643.13592@sjsumcs.sjsu.edu> Organization: U of Waterloo, Ontario Lines: 36 In article <1989Dec5.195643.13592@sjsumcs.sjsu.edu >, 33014-18@sjsumcs.sjsu.edu (Eduardo Horvath) writes: > In article <62298@aerospace.AERO.ORG> abbott@aero.UUCP (Russell J. Abbott) writes: > >In article <32106@watmath.waterloo.edu> gjditchfield@watmsg.waterloo.edu (Glen Ditchfield) writes: > >> ... In practice, in C++, wouldn't it be simpler to pass a comparison > >>function as an argument to the sort() function? > > > >Can you really do that in C++? What would the declarations look like? > >That would be even more flexible than the generic sort that I asked > >about originally. > > > > This is an old trick from C. You pass a pointer to a function as > an argument to a sort function, and the sort function calls the comparison. ... non-C++ example deleted > b) Linkage problems occuring from compiling different object modules > with different function declarations. This was a problem with > classic C, but in ANSI C or C++, correct prototyping and > recompiling all files where prototypes have been changed will > usually solve this problem. > > I hope this helps. > > > Eduardo Horvath | San Jose State | 33014-18@sjsumcs.SJSU.EDU As you mentioned, C++ has correct prototyping, and the qsort example you have above relies on defeating the prototyping when passing the comparison function as a parameter. I agree with Glen that there is no (type safe) way to do this in C++. -- Gordon V. Cormack CS Dept, University of Waterloo, Canada N2L 3G1 gvcormack@waterloo.EDU gvcormack@uwaterloo.CA gvcormac@water.BITNET