Skip to content

Instantly share code, notes, and snippets.

@dmikurube
Created January 20, 2012 06:42
Show Gist options
  • Save dmikurube/1645800 to your computer and use it in GitHub Desktop.
Save dmikurube/1645800 to your computer and use it in GitHub Desktop.
#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