Skip to content

Instantly share code, notes, and snippets.

@maxdeliso
Last active December 14, 2015 00:39
Show Gist options
  • Select an option

  • Save maxdeliso/5000660 to your computer and use it in GitHub Desktop.

Select an option

Save maxdeliso/5000660 to your computer and use it in GitHub Desktop.
example of late binding with c++
#include <iostream>
struct Foo {
virtual int retrieve() = 0;
};
struct Bar : public Foo {
inline int retrieve() {
return 1;
}
};
struct Baz : public Foo {
inline int retrieve() {
return 2;
}
};
int main() {
Bar bar;
Baz baz;
/* outputs "1 2" because of late binding */
std::cout
<< bar.retrieve() << " "
<< baz.retrieve() << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment