Make some Animal methods pure virtual
authorLukas Jiriste <ljiriste@student.42prague.com>
Fri, 25 Oct 2024 11:08:40 +0000 (13:08 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Fri, 25 Oct 2024 11:08:40 +0000 (13:08 +0200)
There already were some pure virtual methods so the task was fulfilled
in ex01 already. It maybe should not have been.

For the evaluator of ex01: The Animal may not be abstract by removing
the pure virtual methods. The methods then have to be called from main
through dynamic_casting the Animal pointers to the Derived pointer
types, which have the methods defined.

ex02/Animal.cpp
ex02/Animal.h

index fff5e5e846697075f79584d2f3c03053815a3045..04ac752d5f95626edf7d43cbc520160b396c698f 100644 (file)
@@ -26,8 +26,6 @@ Animal        &Animal::operator=(const Animal &other)
        return (*this);
 }
 
-// This would better be purely virtual function but the subject mandates that
-// even the base must implement this function.
 void   Animal::makeSound() const
 {
        std::cout << "BASE ANIMAL SOUNDS\n";
index 83361a2ebd39cdd34ec2711bd212599a9aab8765..e1d09bee34ac9c80451fac6721eb37a4528e0181 100644 (file)
@@ -15,8 +15,8 @@ class Animal
 
                virtual Animal  &operator=(const Animal &other);
 
-               virtual void    makeSound() const;
                std::string             getType() const;
+               virtual void    makeSound() const = 0;
                virtual void    listIdeas() const = 0;
                virtual void    addIdea(std::string idea) = 0;
 };