Created
January 20, 2012 06:42
-
-
Save dmikurube/1645800 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; | |
class parent_t { | |
public: | |
void print_it() { | |
local_print(); | |
} | |
virtual void local_print() { | |
cout << "parent" << endl; | |
} | |
virtual void inner_print() { | |
print_it(); | |
} | |
}; | |
class child_t : public parent_t { | |
virtual void local_print() { | |
cout << "child" << endl; | |
} | |
}; | |
int main() | |
{ | |
parent_t p; | |
child_t c; | |
p.print_it(); // => parent | |
c.print_it(); // => child | |
p.inner_print(); // => parent | |
c.inner_print(); // => child | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment