🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #812

Re: Dynamic Binding by Argument Type

#812
From: Harald Fuchs
Date: Tue, 05 Feb 1991 16:55
39 lines
1524 bytes
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 <fuchs@telematik.informatik.uni-karlsruhe.de>
<fuchs@telematik.informatik.uni-karlsruhe.dbp.de>   *gulp*
Technical Details
Message-ID: <fuchs.665772943@tmipi4>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!caen!sol.ctr.columbia.edu!ira.uka.de!fuchs
References: <2715@meaddata.meaddata.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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: <fuchs.665772943@tmipi4>
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