Created
June 22, 2013 10:56
-
-
Save flyx/5840444 to your computer and use it in GitHub Desktop.
This file contains 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 <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