dynamic dispatch on operator arguments?

From: Mark P (not_at_my.real.email)
Date: 11/05/04


Date: Fri, 05 Nov 2004 12:12:39 -0800

Say I have a base class B and a derived class D.

Now I have some other class C in which I want to provide two functions:

void C::f(B* bObj);
void C::f(D* dObj);

The goal is that the version of f called should be determined by the
dynamic type of its argument. So if I had

C cObj;
B *pD = new D();
cObj.f(pD);

then cObj.f(pD) should call the second (D*) version of the function even
though the static type of pD is B*.

Is such a thing possible? If so, how?

Thanks,
Mark



Relevant Pages

  • Re: dynamic dispatch on operator arguments?
    ... > Say I have a base class B and a derived class D. ... > dynamic type of its argument. ... Alwyn ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Application.Run() problem
    ... still am very much confused about the paint event handler. ... It most obviously should be the derived class, ... It seems that you're not understanding how inheritance works. ... which ensures that the base class uses the same ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Very Confused on Page 33
    ... On page 33 Bruce is explaining inheritance. ... > base class you can also send to objects of the derived class. ... The programmatic difference enables the subclass ...
    (comp.lang.java.help)
  • Re: attribute or subclass
    ... With inheritance the derived class code ... reference in place of the base class reference. ...
    (comp.object)
  • Re: C# inheritance broken?
    ... class as a derived class, you can do the opposite though. ... Ignacio Machin ... issue of inheriting a base class ... You can't use a base class instance as though it were a derived class ...
    (microsoft.public.dotnet.languages.csharp)