Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class B{
  6. public:
  7. virtual void call() { cout<<"Bn"; };
  8. };
  9.  
  10. class D: public B{
  11. public:
  12. void call() { cout<<"Dn"; }
  13. };
  14.  
  15. int _tmain(int argc, _TCHAR* argv[])
  16. {
  17. B b;
  18. D d;
  19.  
  20. b.call(); // output is "B"
  21.  
  22. d.call(); // output is "D"
  23.  
  24. B* obj = &d;
  25. obj->call(); // output is "D"
  26.  
  27. return 0;
  28. }
  29.  
  30. Base * obj = &DerivedA;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement