42/CPP_Module_04
13 months agoAdd IMateriaSource interface and an implementation
Lukas Jiriste [Fri, 25 Oct 2024 13:17:27 +0000 (15:17 +0200)]
Add IMateriaSource interface and an implementation

I'm a little torn whether to provide the assignment operator.
The AMateria has const member which forbids any meaningful assignment,
the MateriaSource however does not have any such limitation.
I think the MateriaSource would not by able to be changed "in-game" and
making assignment not possible conveys this idea.
But the assignment could be useful for object reuse...
I left the assignment operator private, but provided implementation to
not make future laziness stand in the way of change.

13 months agoAdd abstract class AMateria and 2 child classes
Lukas Jiriste [Fri, 25 Oct 2024 13:06:02 +0000 (15:06 +0200)]
Add abstract class AMateria and 2 child classes

13 months agoMake some Animal methods pure virtual
Lukas Jiriste [Fri, 25 Oct 2024 11:08:40 +0000 (13:08 +0200)]
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.

13 months agoCopy ex01 to ex02
Lukas Jiriste [Fri, 25 Oct 2024 11:05:53 +0000 (13:05 +0200)]
Copy ex01 to ex02

13 months agoChange Makefile to invoke g++ -MM for dependencies
Lukas Jiriste [Fri, 25 Oct 2024 11:00:04 +0000 (13:00 +0200)]
Change Makefile to invoke g++ -MM for dependencies

The g++ -MM $(SOURCES) creates dependency list (without system deps) for
all the sources in a format suitable for Makefile.

I don't like using g++ just after making use of clang++ explicit as I
don't know whether both of those are usually present on PCs.
The solution would probably be to provide the g++ incompatible flag
conditionally when c++ == clang++.

13 months agoFix Brain behaviour
Lukas Jiriste [Fri, 25 Oct 2024 10:41:13 +0000 (12:41 +0200)]
Fix Brain behaviour

13 months agoAdd flag to Makefile
Lukas Jiriste [Fri, 25 Oct 2024 10:36:19 +0000 (12:36 +0200)]
Add flag to Makefile

The 42 computers have c++ pointed to clang++. Clang obscures the
std::string type in gdb even with -g flag, but the option
-fno-limit-debug-info makes std::string legible.
So I added he flag but it is not used in g++ which could be hiding under
c++, so I've rewritten the Makefile to explicitly use clang++.

13 months agoUse Brain in Dog and Cat classes, use it in main
Lukas Jiriste [Fri, 25 Oct 2024 10:31:55 +0000 (12:31 +0200)]
Use Brain in Dog and Cat classes, use it in main

13 months agoAdd method for brain to acquire and express ideas
Lukas Jiriste [Fri, 25 Oct 2024 08:33:21 +0000 (10:33 +0200)]
Add method for brain to acquire and express ideas

13 months agoAdd Brain class and use it in Cat and Dog
Lukas Jiriste [Fri, 25 Oct 2024 08:01:50 +0000 (10:01 +0200)]
Add Brain class and use it in Cat and Dog

This is an exercise in ownership handling, so Dog and Cat contain a
pointer to Brain that they have to correctly manage.

13 months agoCopy ex00 to ex01
Lukas Jiriste [Fri, 25 Oct 2024 07:44:20 +0000 (09:44 +0200)]
Copy ex00 to ex01

13 months agoExtend main.cpp, make Animal destr virtual in ex00
Lukas Jiriste [Fri, 25 Oct 2024 07:28:53 +0000 (09:28 +0200)]
Extend main.cpp, make Animal destr virtual in ex00

Extend main.cpp by the Wrong- classes and add delete to call the
destructors. For the delete to work properly, the Animal destructor is
changed to a virtual one.

13 months agoImplement the solution to ex00
Lukas Jiriste [Thu, 24 Oct 2024 16:54:58 +0000 (18:54 +0200)]
Implement the solution to ex00