Path: utzoo!news-server.csri.toronto.edu!cs.utexas.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.... Keywords: fyi Message-ID: <11764@pasteur.Berkeley.EDU> Date: 7 Mar 91 22:32:33 GMT Sender: news@pasteur.Berkeley.EDU Reply-To: maverick@fir.Berkeley.EDU (Vance Maverick) Lines: 50 To all those who have responded via mail or news -- I was obviously unclear about what I wanted to accomplish. I want to use a single List class to maintain sorted homogeneous lists of various essentially unrelated classes. The best solution I've seen is double-dispatch, which is type-safe and accomplishes what I want to, though it makes for obscure code. For example, if we have class Base { public: virtual int operator < (const Base &) = 0; virtual int operator >= (const Base &) = 0; }; class IntVal : public Base { public: int val; int operator < (const IntVal &i) { return (val < i.val); } int operator >= (const IntVal &i) { return (val >= i.val); } /* Comparing an IntVal to a Base? Flip the arguments to see if the Base isn't really an IntVal after all */ int operator < (const Base &b) { return (b >= *this); } }; class FloatVal : public Base { public: float val; int operator < (const FloatVal &f) { return (val < f.val); } int operator >= (const FloatVal &f) { return (val >= f.val); } /* Comparing a FloatVal to a Base? Flip the arguments to see if the Base isn't really a FloatVal after all */ int operator < (const Base &b) { return (b >= *this); } }; then comparisons of Base objects will invoke a comparison of values only if the derived types match at runtime. Thanks for the response, Vance