Muzer

Fish - inherintance without virtual.

Feb 15th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class Animal
  4. {
  5.   public:
  6.     void move();
  7. };
  8.  
  9. void Animal::move()
  10. {
  11.   std::cout << "Moving generically." << std::endl;
  12. }
  13.  
  14. class Fish : public Animal
  15. {
  16.   public:
  17.     void move();
  18. };
  19.  
  20. void Fish::move()
  21. {
  22.   std::cout << "Swimming, because that's what fish do." << std::endl;
  23. }
  24.  
  25. int main()
  26. {
  27.   Animal *bob = new Fish();
  28.   bob->move();
  29.   ((Fish *)bob)->move();
  30. }
Advertisement
Add Comment
Please, Sign In to add comment