Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. MAIN.CPP
  2.  
  3. #include <iostream>
  4. #include "Pet.h"
  5. #include "Cat.h"
  6. #include "Dog.h"
  7. using namespace std;
  8.  
  9. int main() {
  10. setlocale(LC_ALL, "rus");
  11. Pet *cat, *dog, *bee;
  12. Cat matroskin;
  13. Dog sharik;
  14. cat = &matroskin;
  15. dog = &sharik;
  16. cat->voice();
  17. dog->voice();
  18. return 0;
  19. }
  20.  
  21. PET.H
  22.  
  23. #pragma once
  24. class Pet
  25. {
  26. public:
  27. Pet();
  28. virtual void voice() = 0;
  29. };
  30.  
  31. CAT.H
  32.  
  33. #pragma once
  34. #include <iostream>
  35. #include "Pet.h"
  36. class Cat : virtual public Pet
  37. {
  38. public:
  39. Cat();
  40. virtual void voice() {
  41. std::cout << "Мяв\n";
  42. }
  43. };
  44.  
  45. DOG.H
  46.  
  47. #pragma once
  48. #include <iostream>
  49. #include "Pet.h"
  50. class Dog : virtual public Pet
  51. {
  52. public:
  53. Dog();
  54. virtual void voice() {
  55. std::cout << "Гав\n";
  56. }
  57. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement