Advertisement
chrisasl

Untitled

Feb 15th, 2012
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Base
  5. {
  6.     public:
  7.     virtual void print() { cout << "Base print" << endl;}
  8. };
  9.  
  10. class DerivedA : public Base
  11. {
  12.     public:
  13.     virtual void print() { cout << "Derived_A print" << endl;}
  14. };
  15.  
  16. class DerivedB : public DerivedA
  17. {
  18.     public:
  19.     virtual void print() {cout << "Derived_B print" << endl;}
  20. };
  21.  
  22. int main()
  23. {
  24.     DerivedB b;
  25.    
  26.     Base* ptr = &b;
  27.     ptr->print();
  28.    
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement