From: Lukas Jiriste Date: Fri, 25 Oct 2024 11:08:40 +0000 (+0200) Subject: Make some Animal methods pure virtual X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=4f58f18498991ac125004f27129839602086daaa;p=42%2FCPP_Module_04 Make some Animal methods pure virtual 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. --- diff --git a/ex02/Animal.cpp b/ex02/Animal.cpp index fff5e5e..04ac752 100644 --- a/ex02/Animal.cpp +++ b/ex02/Animal.cpp @@ -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"; diff --git a/ex02/Animal.h b/ex02/Animal.h index 83361a2..e1d09be 100644 --- a/ex02/Animal.h +++ b/ex02/Animal.h @@ -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; };