Skip to content

Instantly share code, notes, and snippets.

@clalancette
Created September 15, 2020 19:02
Show Gist options
  • Save clalancette/7f9c82aa0db15a6a362a0dda700b657a to your computer and use it in GitHub Desktop.
Save clalancette/7f9c82aa0db15a6a362a0dda700b657a to your computer and use it in GitHub Desktop.
Overloaded virtual example
#include <cstdio>
class Base
{
public:
virtual void foo()
{
fprintf(stderr, "Foo no argument\n");
}
};
class Foo : public Base
{
public:
virtual void foo(int bar)
{
fprintf(stderr, "Foo argument %d\n", bar);
}
};
int main()
{
Foo *x = new Foo();
Base *y = static_cast<Base *>(x);
x->foo(4);
y->foo();
delete x;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment