Commit 80ad0ce6 authored by Sokolov Viacheslav's avatar Sokolov Viacheslav

Initial commit: introduce pets

parents
target/bitset: code/*.h code/*.cpp | target
g++ -fsanitize=address --std=c++17 code/*.cpp -o target/example
target:
mkdir target
clean:
rm -rf target
#include "animal.h"
Animal::~Animal() = default;
#pragma once
class Animal
{
public:
virtual ~Animal();
virtual void interact() = 0;
};
#include "cat.h"
#include <cstdio>
Cat::Cat(std::string name)
: mName(name)
{
}
Cat::~Cat()
{
printf("%s of %s leaves you alone\n", name().c_str(), breed().c_str());
}
std::string Cat::name()
{
return mName;
}
std::string Cat::breed()
{
return "SuperKitty2003@WiLlMaKeYoUcRy";
}
#pragma once
#include "pet.h"
class Cat final : public Pet
{
public:
explicit Cat(std::string name);
~Cat() final;
private:
std::string name() override;
std::string breed() override;
std::string mName;
};
#include "cat.h"
int main()
{
Cat cat{"Nagibator666"};
cat.interact();
}
#include "pet.h"
#include <cstdio>
Pet::~Pet() = default;
void Pet::interact()
{
printf("My dear %s of the %s breed, come and take meal with me!\n", name().c_str(), breed().c_str());
}
#pragma once
#include "animal.h"
#include <string>
class Pet : public Animal
{
public:
~Pet() override;
void interact() final;
protected:
virtual std::string name() = 0;
virtual std::string breed() = 0;
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment