Re: dynamic dispatch on operator arguments?
From: Alwyn (dt015a1979_at_mac.com.invalid)
Date: 11/05/04
- Next message: Jerry Coffin: "Re: Difference between template <typename T> and template <class T>"
- Previous message: Watson Davis: "Re: Any solution ??"
- In reply to: Mark P: "dynamic dispatch on operator arguments?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 05 Nov 2004 21:01:18 +0000
In article <cmgmrn0m4r@enews4.newsguy.com>, Mark P <not@my.real.email>
wrote:
>
> 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?
Both Coplien and Alexandrescu discuss how to implement multimethods in
their respective books, but it is far from trivial.
For Alexandrescu's solution, see:
<http://www.visualco.de/idiom/samples/Loki/html/c$$lib$Loki$Reference$Mu
ltiMetho8.html>
HTH
Alwyn
- Next message: Jerry Coffin: "Re: Difference between template <typename T> and template <class T>"
- Previous message: Watson Davis: "Re: Any solution ??"
- In reply to: Mark P: "dynamic dispatch on operator arguments?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|