Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MAIN.CPP
- #include <iostream>
- #include "Pet.h"
- #include "Cat.h"
- #include "Dog.h"
- using namespace std;
- int main() {
- setlocale(LC_ALL, "rus");
- Pet *cat, *dog, *bee;
- Cat matroskin;
- Dog sharik;
- cat = &matroskin;
- dog = &sharik;
- cat->voice();
- dog->voice();
- return 0;
- }
- PET.H
- #pragma once
- class Pet
- {
- public:
- Pet();
- virtual void voice() = 0;
- };
- CAT.H
- #pragma once
- #include <iostream>
- #include "Pet.h"
- class Cat : virtual public Pet
- {
- public:
- Cat();
- virtual void voice() {
- std::cout << "Мяв\n";
- }
- };
- DOG.H
- #pragma once
- #include <iostream>
- #include "Pet.h"
- class Dog : virtual public Pet
- {
- public:
- Dog();
- virtual void voice() {
- std::cout << "Гав\n";
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement