dynamic-dispatch

Work around Java's static method dispatching without Double Dispatch/Visitor patterns

I am using a class Foo that provides these methods: String overloadedMethod(Object) String overloadedMethod(Goo) Since Java statically dispatches on the non-receiver argument, I cannot just pass my value (which is an Object, but might have dynamic type Goo) and rely on the JVM to dynamically choose the "correct" method. This is my cu...

Reflection or Dynamic Dispatching

I'm writing a abstract file parser (C#) which is extended by two concrete parsers. Both need to perform several checks. Currently there is a validate method in the abstract parser, which uses reflection to call all methods with a name starting with 'test'. That way adding checks is as easy as adding a method with a name that starts with ...

Emulating Dynamic Dispatch in C++ based on Template Parameters

This is heavily simplified for the sake of the question. Say I have a hierarchy: struct Base { virtual int precision() const = 0; }; template<int Precision> struct Derived : public Base { typedef Traits<Precision>::Type Type; Derived(Type data) : value(data) {} virtual int precision() const { return Precision; } ...

Why doesn't C++ allow you to request a pointer to the most derived class?

(This question should probably be answered with a reference to Stroustrup.) It seems extremely useful to be able to request a pointer to the most derived class, as in the following: class Base { ... }; class DerivedA { ... }; class DerivedB { ... }; class Processor { public: void Do(Base* b) {...} void Do(DerivedA* d) {...} voi...

suspicions of multithreading race conditions in c++ virtual calls w/ vtable implementation

I have a suspicion that there might be a race condition in a certain C++ multithreading situation involving virtual method calls in a vtable dynamic dispatching implementation (for which a vtable pointer is stored as a hidden member in the object with virtual methods). I would like to confirm whether or not this is actually an issue, an...

Is the Visitor Pattern the fastest way to differentiate parameter types in C++?

Is the Visitor Pattern the fastest way to accomplish method parameter type identification (effectively single dispatch on a parameter, not a member's class) in C++? I might know the exact method(s) I want to invoke on elements of not-yet-know subtype, so invariably making an additional virtual method call like V::visit(A *) in A::accept...