Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!spool.mu.edu!uwm.edu!bionet!agate!pasteur!fir.Berkeley.EDU!maverick From: maverick@fir.Berkeley.EDU (Vance Maverick) Newsgroups: comp.lang.c++ Subject: Lacking parameterized types and multi-methods.... Message-ID: <11687@pasteur.Berkeley.EDU> Date: 5 Mar 91 17:26:34 GMT Sender: news@pasteur.Berkeley.EDU Reply-To: maverick@fir.Berkeley.EDU (Vance Maverick) Lines: 32 I have a problem for which I have not yet found a clean solution in C++. In my application, there are various classes of which I wish to keep lists. So I define a single class List, which handles objects of class Listable, and I make all the things I want lists of (musical notes, names, and other incompatible types) subclasses of Listable. So far so good; but I want the List code to be able to compare two objects, so it can insert items in sorted order, where this matters. I define a virtual member function (actually it's an overloaded operator, but same difference) on Listable, taking an argument of type Listable. On Name, I define such a function taking an argument of type Name; similarly, a Note member function comparing two Notes. So in my insertion code, I have something like this: Listable *member, *newvalue; if (*newvalue < *member) .... Unfortunately, this can't invoke my Note-to-Note or Name-to-Name comparator, since the signature of these functions contains the derived type, and C++ uses the declared type of the right-hand argument in selecting the function to call. To get this to work, I need to define alternate comparators, comparing Note to Listable and Name to Listable. This is unpleasant, because it involves a distasteful cast in the alternate comparator, and because it now allows me to explicitly compare a Note to a Name. Does anybody have a suggestion for how to do this "correctly", lacking parameterized types and runtime method selection on multiple arguments? Thanks, Vance