Skip to content

Instantly share code, notes, and snippets.

@flyx
Created June 22, 2013 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flyx/5840444 to your computer and use it in GitHub Desktop.
Save flyx/5840444 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
struct A {
void put() {
cout << "A" << endl;
}
virtual void vPut() {
cout << "A" << endl;
}
};
struct B : public A {
void put() {
cout << "B" << endl;
}
virtual void vPut() {
cout << "B" << endl;
}
};
struct C : public B {
void put() {
cout << "C" << endl;
}
virtual void vPut() {
cout << "C" << endl;
}
};
int main() {
C* c = new C();
c->put();
c->vPut();
dynamic_cast<B*>(c)->put();
dynamic_cast<B*>(c)->vPut();
dynamic_cast<A*>(c)->put();
dynamic_cast<A*>(c)->vPut();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment