Created
September 15, 2020 19:02
-
-
Save clalancette/7f9c82aa0db15a6a362a0dda700b657a to your computer and use it in GitHub Desktop.
Overloaded virtual example
This file contains hidden or 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 <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