Created
May 30, 2015 03:16
-
-
Save mirekfranc/c27874fa04210d937641 to your computer and use it in GitHub Desktop.
clearing up the terminology...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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