Re: Multiple dispatch
"jam" <farid.mehrabi@gmail.com> wrote in message
news:1174339506.501270.266070@e65g2000hsc.googlegroups.com...
On Mar 19, 10:05 pm, "Grizlyk" <grizl...@yandex.ru> wrote:
Also why have you called this stuff as "multiple dispath"? It looks
like special implemetation of "single dispatch" with "type of class"
as single dispatch selector.
As i know multiple dispatch is something, that has other dispath
selectors, in addition to "class of object", for example, first
parametter of function can be second dispatch selector.
I call that a normal overloading. Different name mangling is exerted on
functions with different params but that is not curently the case for
functions with same name and prototype which leads in a complete
hiding behavoir. Note that we expect different behavoir when calling
'go' from an 'A' or a 'D' pointer/reference.So correct dispaching
will be important.
Yet your example is still single dispatch, and you probably misunderstood
Maksim. The only dispatching selector involved is the class instance pointer
you use to call the function upon. Multiple dispatch is when you use more
than one selector (not available in C++98 but perhaps in C++0x).
Example of single dispatch:
struct Base { virtual void foo(); }
struct Derived : public Base { void foo(); };
Base * b = new Derived();
b->foo(); // calls Derived::foo
The above uses single dispatch because it only dispatches on one parameter:
the 'b' pointer. Whether the vtable entry for foo() points to a method of a
class that is overloaded for several base classes doesn't make it multi
dispatch. There is only 1 dispatch parameter.
Example of multi dispatch (using syntax from the n2216 proposal):
void bar(virtual Base * a, virtual Base * b);
void bar(virtual Base * a, virtual Derived * b);
void bar(virtual Derived * a, virtual Derived * b);
void bar(virtual Derived * a, virtual Derived * b);
// the following calls are all multi dispatch - they use both parameters to
select the appropriate overloaded function at runtime
// note that the compiletime-type of both 'b' and 'd' is Base*
Base *b = new Base(), *d = new Derived();
bar(b, b); // calls bar(Base*, Base*)
bar(b, d); // calls bar(Base*, Derived*)
bar(d, b); // calls bar(Derived*, Base*)
bar(d, d); // calls bar(Derived*, Derived*)
Of course this is 'overloading' because bar is overloaded, but it is also
multi-dispatch because the runtime-types of both parameters are used to
select the right function. That makes the call to bar multiple dispatch
More information is in n2216
(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2216.pdf)
- Sylvester Hesp
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]