Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!cs.utexas.edu!uunet!cimshop!davidm From: cimshop!davidm@uunet.UU.NET (David S. Masterson) Newsgroups: comp.lang.c++ Subject: Re: Seeking neat way to do binary "virtual" functions. Message-ID: Date: 24 Mar 91 21:33:34 GMT References: <13683@darkstar.ucsc.edu> Sender: davidm@cimshop.UUCP Distribution: comp Organization: Consilium Inc., Mountain View, California Lines: 33 In-reply-to: ericg@ucschu.ucsc.edu's message of 21 Mar 91 21:14:22 GMT >>>>> On 21 Mar 91 21:14:22 GMT, ericg@ucschu.ucsc.edu (Eric Goodman) said: Eric> What I want: Eric> class B { Eric> virtual B& operator+(B&); Eric> }; Eric> class D: public B{ Eric> B& operator+(D&); Eric> }; Eric> the D::operator+() function is not overloaded. I'd like a mechanism Eric> that would check the actual type of the second arguent, and call the Eric> correct function at run time: Eric> B& f(B& one, B& two) { Eric> return (one+two); // if (either or) both are B's, use Eric> // B::operator+(B&) Eric> // if both are D's, use Eric> // D::operator+(D&) Eric> }; Something that might be of interest is the article on "Generalized Arithmetic in C++" by Tim Budd in the February issue of the Journal of Object-Oriented Programming. It describes a couple of techniques (coercive generality and double polymorphism) that might show good ways of doing this and the pitfalls. -- ==================================================================== David Masterson Consilium, Inc. (415) 691-6311 640 Clyde Ct. uunet!cimshop!davidm Mtn. View, CA 94043 ==================================================================== "If someone thinks they know what I said, then I didn't say it!"