multiple-dispatch

Multiple dispatch solution with full maintainability

一世执手 提交于 2019-11-27 06:32:52
问题 Can someone think of a good way to implement multiple dispatch with something like the Object::foo overloads below? class A { public: virtual void accept (Visitor&) = 0; }; class B : public A { virtual void accept (Visitor&) override; }; class C : public A { virtual void accept (Visitor&) override; }; class D : public A { virtual void accept (Visitor&) override; }; class Object { public: virtual double foo (A*, A*) { std::cout << "Object::foo A,A\n"; return 3.14; } virtual double foo (B*, B*)

Is C# a single dispatch or multiple dispatch language?

隐身守侯 提交于 2019-11-27 01:04:19
问题 I'm trying to understand what single and multiple dispatch are, exactly. I just read this: http://en.wikipedia.org/wiki/Multiple_dispatch And from that definition is seems to me that C# and VB.Net are multiple-dispatch, even though the choice of which overload to call is made at compile-time. Am I correct here, or am I missing something? Thanks! 回答1: OK, I understood the subtle difference where function overloading is different from multiple-dispatch. Basically, the difference is whether

Multiple dispatch in C++

北战南征 提交于 2019-11-26 22:07:58
I am trying to understand what multiple dispatch is. I read a lot of various texts but I still have no idea what multiple dispatch is and what it is good for. Maybe the thing I am missing is piece of code using multiple dispatch. Please, can you write a little piece of code in C++ using multiple dispatch so that I can see it cannot be compiled/runned properly because C++ has only single dispatch? I need to see the difference. Thanks. Multi-dispatch is the ability to choose which version of a function to call based on the runtime type of the arguments passed to the function call. Here's an