Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!caen!sol.ctr.columbia.edu!ira.uka.de!fuchs From: fuchs@it.uka.de (Harald Fuchs) Newsgroups: comp.std.c++ Subject: Re: Dynamic Binding by Argument Type Message-ID: Date: 5 Feb 91 16:55:43 GMT References: <2715@meaddata.meaddata.com> Sender: news@ira.uka.de (USENET News System) Organization: University of Karlsruhe, FRG Lines: 39 johnt@meaddata.com (John Townsend) writes: >Now, consider this: > b1 = &b2; > g(*b1); // Calls g(Base &arg) > b1 = &d1; > g(*b1); // STILL calls g(Base &arg), even though *b1 is a Derived > // object! >Why is it that *b1 is treated as a Derived object when it is the invoking >object, but as a Base object when it is the argument? Is this intentional? Me thinks so. There is no way you could tell g's argument to use static or dynamic binding. What you might want is something like void g (virtual Base&); but that's not C++. >It seems somewhat inconsistent to me. Is there some way to dynamically bind >to the overloaded g() based on its argument type? Sure: class Base { public: virtual void f(); virtual void g (); } class Derived: public Base { public: void f(); void g (); } inline void g (Base& arg) { arg.g (); } -- Harald Fuchs *gulp*