Skip to content

Instantly share code, notes, and snippets.

@fhd
Created October 30, 2011 12:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fhd/1325846 to your computer and use it in GitHub Desktop.
Save fhd/1325846 to your computer and use it in GitHub Desktop.
Duck typing in C++
class Duck {
public:
void fly()
{
...
}
void swim()
{
...
}
};
class Penguin {
public:
void swim()
{
...
}
void slide()
{
...
}
};
template<T>
void do_stuff_to_a_bird(T bird)
{
bird.fly();
}
int main(int argc, char* argv[])
{
Duck duck;
Penguin penguin;
do_stuff_to_a_bird(duck);
do_stuff_to_a_bird(penguin);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment