Commit 8cd5d59d authored by Sokolov Viacheslav's avatar Sokolov Viacheslav

Introduce new entities. Unfortunately it does not compile!

parent 80ad0ce6
......@@ -9,15 +9,15 @@ Cat::Cat(std::string name)
Cat::~Cat()
{
printf("%s of %s leaves you alone\n", name().c_str(), breed().c_str());
printf("%s of %s leaves you alone.\n", name().c_str(), breed().c_str());
}
std::string Cat::name()
std::string Cat::name() const
{
return mName;
}
std::string Cat::breed()
std::string Cat::breed() const
{
return "SuperKitty2003@WiLlMaKeYoUcRy";
}
......@@ -2,15 +2,15 @@
#include "pet.h"
class Cat final : public Pet
class Cat : public Pet
{
public:
explicit Cat(std::string name);
~Cat() final;
~Cat();
private:
std::string name() override;
std::string breed() override;
std::string name() const override;
std::string breed() const override;
std::string mName;
};
#include "cat.h"
#include <cstdio>
#pragma once
#include "pet.h"
class Dog final : private Pet
{
std::string name();
std::string breed();
};
#pragma once
#include "animal.h"
class Human : private Animal
{
public:
virtual Pet& getPat() = 0;
};
#include "cat.h"
#include "tiger.h"
#include "man.h"
#include "woman.h"
int main()
{
Cat cat{"Nagibator666"};
{
Cat cat{"Nagibator666"};
cat.interact();
}
cat.interact();
{
Man man;
man.interact();
}
{
Woman woman;
woman.interact();
}
{
Tiger tiger{"LazyOne"};
tiger.interact();
Cat clonedTiger = tiger;
clonedTiger.interact();
}
}
#include "human.h"
class Man final : public Human
{
};
......@@ -2,7 +2,10 @@
#include <cstdio>
Pet::~Pet() = default;
Pet::~Pet()
{
printf("%s was a good pet.\n", name().c_str());
}
void Pet::interact()
{
......
......@@ -12,6 +12,6 @@ public:
void interact() final;
protected:
virtual std::string name() = 0;
virtual std::string breed() = 0;
virtual std::string name() const = 0;
virtual std::string breed() const = 0;
};
#include "tiger.h"
Tiger::Tiger(std::string name)
: Cat{name}
{
}
std::string Tiger::breed() const
{
return "TIGERALLMIGHTY";
}
#pragma once
#include "cat.h"
class Tiger final : public Cat
{
public:
explicit Tiger(std::string name);
std::string breed() const override;
};
#pragma once
#include "human.h"
class Woman final : public Human
{
};
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