Guest User

Untitled

a guest
Jan 23rd, 2021
20
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. class Animal {
  4. public:
  5. Animal(const char * name) : name(name) {};
  6. virtual ~Animal() {}
  7.  
  8. virtual void Pet() = 0;
  9. private:
  10. const char * name;
  11. };
  12.  
  13. class Dog : public Animal {
  14. public:
  15. Dog(const char * name) : Animal(name) {};
  16. virtual ~Dog() {}
  17.  
  18. virtual void Pet() {
  19. std::cout << "Petted a dog!" << std::endl;
  20. }
  21. private:
  22. };
  23.  
  24. class Cat : public Animal {
  25. public:
  26. Cat(const char * name) : Animal(name) {};
  27. virtual ~Cat() {}
  28.  
  29. virtual void Pet(){
  30. std::cout << "Petted a cat!" << std::endl;
  31. }
  32. };
  33.  
  34. class Snoopy : public Dog {
  35. public:
  36. Snoopy() : Dog("Snoopy") {};
  37. virtual ~Snoopy() {}
  38.  
  39. virtual void Pet() {
  40. std::cout << "Petted snoopy!" << std::endl;
  41. }
  42. };
  43.  
  44. class Garfield : public Cat {
  45. public:
  46. Garfield() : Cat("Garfield") {};
  47. virtual ~Garfield() {}
  48.  
  49. virtual void Pet() {
  50. std::cout << "Petted a garfield!" << std::endl;
  51. }
  52. };
  53.  
  54. int main() {
  55. Cat* garfield = new Garfield();
  56. garfield->Pet();
  57. delete garfield;
  58. return 0;
  59. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×