Skip to content

Instantly share code, notes, and snippets.

@mirekfranc
Created May 30, 2015 03:16
Show Gist options
  • Save mirekfranc/c27874fa04210d937641 to your computer and use it in GitHub Desktop.
Save mirekfranc/c27874fa04210d937641 to your computer and use it in GitHub Desktop.
clearing up the terminology...
#include <iostream>
using namespace std;
struct A { virtual void f () { cout << "A" << endl; }};
struct B: A { void f () { cout << "B" << endl; }};
/* multiple static dispatch */
void overload (int, A *a, B *b)
{
cout << "int a b" << endl;
a->f (); /* single dynamic dispatch */
}
void overload (int, B *b, A *a)
{
cout << "int b a" << endl;
b->f ();
}
int
main ()
{
B var;
A *a = &var;
B *b = &var;
overload (0, a, b);
overload (0, b, a);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment