mirror of
https://github.com/Ladebeze66/cpp-partie-1.git
synced 2026-11-09 13:17:15 +01:00
ccp
This commit is contained in:
18
cpp04/ex00/.vscode/c_cpp_properties.json
vendored
Normal file
18
cpp04/ex00/.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "linux-gcc-x64",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "${default}",
|
||||
"cppStandard": "${default}",
|
||||
"intelliSenseMode": "linux-gcc-x64",
|
||||
"compilerArgs": [
|
||||
""
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
24
cpp04/ex00/.vscode/launch.json
vendored
Normal file
24
cpp04/ex00/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "C/C++ Runner: Debug Session",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": false,
|
||||
"cwd": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp04/ex00",
|
||||
"program": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp04/ex00/build/Debug/outDebug",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
67
cpp04/ex00/.vscode/settings.json
vendored
Normal file
67
cpp04/ex00/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"C_Cpp_Runner.cCompilerPath": "gcc",
|
||||
"C_Cpp_Runner.cppCompilerPath": "g++",
|
||||
"C_Cpp_Runner.debuggerPath": "gdb",
|
||||
"C_Cpp_Runner.cStandard": "",
|
||||
"C_Cpp_Runner.cppStandard": "",
|
||||
"C_Cpp_Runner.msvcBatchPath": "",
|
||||
"C_Cpp_Runner.useMsvc": false,
|
||||
"C_Cpp_Runner.warnings": [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Wpedantic",
|
||||
"-Wshadow",
|
||||
"-Wformat=2",
|
||||
"-Wcast-align",
|
||||
"-Wconversion",
|
||||
"-Wsign-conversion",
|
||||
"-Wnull-dereference"
|
||||
],
|
||||
"C_Cpp_Runner.msvcWarnings": [
|
||||
"/W4",
|
||||
"/permissive-",
|
||||
"/w14242",
|
||||
"/w14287",
|
||||
"/w14296",
|
||||
"/w14311",
|
||||
"/w14826",
|
||||
"/w44062",
|
||||
"/w44242",
|
||||
"/w14905",
|
||||
"/w14906",
|
||||
"/w14263",
|
||||
"/w44265",
|
||||
"/w14928"
|
||||
],
|
||||
"C_Cpp_Runner.enableWarnings": true,
|
||||
"C_Cpp_Runner.warningsAsError": false,
|
||||
"C_Cpp_Runner.compilerArgs": [],
|
||||
"C_Cpp_Runner.linkerArgs": [],
|
||||
"C_Cpp_Runner.includePaths": [],
|
||||
"C_Cpp_Runner.includeSearch": [
|
||||
"*",
|
||||
"**/*"
|
||||
],
|
||||
"C_Cpp_Runner.excludeSearch": [
|
||||
"**/build",
|
||||
"**/build/**",
|
||||
"**/.*",
|
||||
"**/.*/**",
|
||||
"**/.vscode",
|
||||
"**/.vscode/**"
|
||||
],
|
||||
"C_Cpp_Runner.useAddressSanitizer": false,
|
||||
"C_Cpp_Runner.useUndefinedSanitizer": false,
|
||||
"C_Cpp_Runner.useLeakSanitizer": false,
|
||||
"C_Cpp_Runner.showCompilationTime": false,
|
||||
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
||||
"C_Cpp_Runner.msvcSecureNoWarnings": false,
|
||||
"files.associations": {
|
||||
"array": "cpp",
|
||||
"compare": "cpp",
|
||||
"functional": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp"
|
||||
}
|
||||
}
|
||||
48
cpp04/ex00/Animal.cpp
Normal file
48
cpp04/ex00/Animal.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Animal.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/30 19:25:01 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/31 12:06:06 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Animal.hpp"
|
||||
|
||||
Animal::Animal() : type("Undefined")
|
||||
{
|
||||
std::cout << GREEN << "Animal constructor called" << RESET << std::endl;
|
||||
}
|
||||
|
||||
Animal::Animal(const Animal ©) : type(copy.type)
|
||||
{
|
||||
std::cout << GREEN << "Animal copy constructor called. Type is copied as " << type << "." << RESET << std::endl;
|
||||
}
|
||||
|
||||
Animal& Animal::operator=(const Animal &operator_aff)// Protection contre l'auto-affectation
|
||||
{
|
||||
if (this != &operator_aff)
|
||||
{
|
||||
this->type = operator_aff.type;
|
||||
}
|
||||
std::cout << "Animal assignment operator called. Type is set to " << type << "." << std::endl;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Animal::~Animal()
|
||||
{
|
||||
std::cout << RED << "Animal destructor called" << RESET << std::endl;
|
||||
}
|
||||
|
||||
std::string Animal::getType() const
|
||||
{
|
||||
return (this->type);
|
||||
}
|
||||
|
||||
void Animal::makeSound() const
|
||||
{
|
||||
std::cout << MAGENTA << "Some animal sound!" << RESET << std::endl;
|
||||
}
|
||||
44
cpp04/ex00/Animal.hpp
Normal file
44
cpp04/ex00/Animal.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Animal.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/30 19:09:56 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/31 16:31:25 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ANIMAL_HPP
|
||||
#define ANIMAL_HPP
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#define RESET "\033[0m"
|
||||
#define BLACK "\033[30m"
|
||||
#define RED "\033[31m"
|
||||
#define GREEN "\033[32m"
|
||||
#define YELLOW "\033[33m"
|
||||
#define BLUE "\033[34m"
|
||||
#define MAGENTA "\033[35m"
|
||||
#define CYAN "\033[36m"
|
||||
#define WHITE "\033[37m"
|
||||
|
||||
class Animal
|
||||
{
|
||||
protected:
|
||||
std::string type;
|
||||
|
||||
public:
|
||||
Animal();
|
||||
Animal(const Animal ©);
|
||||
virtual Animal& operator=(const Animal &operator_aff);
|
||||
virtual ~Animal();
|
||||
|
||||
std::string getType() const;
|
||||
virtual void makeSound() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
41
cpp04/ex00/Cat.cpp
Normal file
41
cpp04/ex00/Cat.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Cat.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/31 12:52:48 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/31 12:54:23 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Cat.hpp"
|
||||
|
||||
Cat::Cat()
|
||||
{
|
||||
type = "Cat";
|
||||
std::cout << GREEN << "Cat default constructor called. Type is set to " << type << "." << RESET << std::endl;
|
||||
}
|
||||
|
||||
Cat::Cat(const Cat ©) : Animal(copy)
|
||||
{
|
||||
std::cout << CYAN << "Cat copy constructor called. Type is " << type << "." << RESET << std::endl;
|
||||
}
|
||||
|
||||
Cat& Cat::operator=(const Cat &operator_aff)
|
||||
{
|
||||
Animal::operator=(operator_aff);
|
||||
std::cout << MAGENTA << "Cat assignment operator called. Type is now " << type << "." << RESET << std::endl;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Cat::~Cat()
|
||||
{
|
||||
std::cout << RED << "Cat destructor called. Type was " << type << "." << RESET << std::endl;
|
||||
}
|
||||
|
||||
void Cat::makeSound() const
|
||||
{
|
||||
std::cout << "Miaouhh! Miaouhh!" << std::endl;
|
||||
}
|
||||
29
cpp04/ex00/Cat.hpp
Normal file
29
cpp04/ex00/Cat.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Cat.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/31 12:17:01 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/31 12:18:06 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CAT_HPP
|
||||
#define CAT_HPP
|
||||
|
||||
#include "Animal.hpp"
|
||||
|
||||
class Cat : public Animal
|
||||
{
|
||||
public:
|
||||
Cat();
|
||||
Cat(const Cat ©);
|
||||
virtual Cat& operator=(const Cat &operator_aff);
|
||||
virtual ~Cat();
|
||||
|
||||
void makeSound() const override;
|
||||
};
|
||||
|
||||
#endif
|
||||
41
cpp04/ex00/Dog.cpp
Normal file
41
cpp04/ex00/Dog.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Dog.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/31 12:50:56 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/31 12:54:33 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Dog.hpp"
|
||||
|
||||
Dog::Dog()
|
||||
{
|
||||
type = "Dog";
|
||||
std::cout << GREEN << "Dog default constructor called. Type is set to " << type << "." << RESET << std::endl;
|
||||
}
|
||||
|
||||
Dog::Dog(const Dog ©) : Animal(copy)
|
||||
{
|
||||
std::cout << CYAN << "Dog copy constructor called. Type is " << type << "." << RESET << std::endl;
|
||||
}
|
||||
|
||||
Dog& Dog::operator=(const Dog &operator_aff)
|
||||
{
|
||||
Animal::operator=(operator_aff);
|
||||
std::cout << MAGENTA << "Dog assignment operator called. Type is now " << type << "." << RESET << std::endl;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Dog::~Dog()
|
||||
{
|
||||
std::cout << RED << "Dog destructor called. Type was " << type << "." << RESET << std::endl;
|
||||
}
|
||||
|
||||
void Dog::makeSound() const
|
||||
{
|
||||
std::cout << "Woof! Woof!" << std::endl;
|
||||
}
|
||||
29
cpp04/ex00/Dog.hpp
Normal file
29
cpp04/ex00/Dog.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Dog.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/31 12:06:42 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/31 12:16:31 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef DOG_HPP
|
||||
#define DOG_HPP
|
||||
|
||||
#include "Animal.hpp"
|
||||
|
||||
class Dog : public Animal
|
||||
{
|
||||
public:
|
||||
Dog();
|
||||
Dog(const Dog ©);
|
||||
virtual Dog& operator=(const Dog &operator_aff);
|
||||
virtual ~Dog();
|
||||
|
||||
void makeSound() const override;
|
||||
};
|
||||
|
||||
#endif
|
||||
66
cpp04/ex00/Makefile
Normal file
66
cpp04/ex00/Makefile
Normal file
@@ -0,0 +1,66 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/12/27 20:57:42 by fgras-ca #+# #+# #
|
||||
# Updated: 2023/12/31 13:03:33 by fgras-ca ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
LOGO = @echo " __, ____, ____, ____, ____ ____, ___, ____,";\
|
||||
echo "(-| (-/_| (-| \ (-|_, (-|__) (-|_, (- / (-|_,";\
|
||||
echo " _|__, _/ |, _|__/ _|__, _|__) _|__, _/__, _|__,";\
|
||||
echo "( ( ( ( ( ( ( ("
|
||||
|
||||
DEF_COLOR = \033[0m
|
||||
GRAY = \033[0;90m
|
||||
RED = \033[0;91m
|
||||
GREEN = \033[0;92m
|
||||
YELLOW = \033[0;93m
|
||||
BLUE = \033[0;94m
|
||||
MAGENTA = \033[0;95m
|
||||
CYAN = \033[0;96m
|
||||
WHITE = \033[0;97m
|
||||
ORANGE = \033[38;5;214m
|
||||
|
||||
NAME = animal
|
||||
|
||||
SRC = Animal.cpp \
|
||||
Cat.cpp \
|
||||
Dog.cpp \
|
||||
WrongAnimal.cpp \
|
||||
WrongCat.cpp \
|
||||
main.cpp \
|
||||
|
||||
OBJS = ${SRC:.cpp=.o}
|
||||
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Werror -Wextra -std=c++98
|
||||
RM = rm -f
|
||||
|
||||
all : $(NAME)
|
||||
|
||||
$(NAME) : $(OBJS)
|
||||
@echo "$(RED)Compilation fixed... $(DEF_COLOR)"
|
||||
$(CC) $(CFLAGS) $(OBJS) -g -o $(NAME)
|
||||
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./animal" to execute the program!!$(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
clean :
|
||||
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
|
||||
$(RM) $(OBJS)
|
||||
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
fclean : clean
|
||||
@echo "$(RED)Delete program name... $(DEF_COLOR)"
|
||||
$(RM) $(NAME)
|
||||
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
re : fclean all
|
||||
|
||||
.PHONY : all clean fclean re
|
||||
48
cpp04/ex00/WrongAnimal.cpp
Normal file
48
cpp04/ex00/WrongAnimal.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* WrongAnimal.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/31 12:55:01 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/31 12:57:57 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "WrongAnimal.hpp"
|
||||
|
||||
WrongAnimal::WrongAnimal() : type("WrongAnimal")
|
||||
{
|
||||
std::cout << GREEN << "WrongAnimal default constructor called. Type is set to " << type << "." << RESET << std::endl;
|
||||
}
|
||||
|
||||
WrongAnimal::WrongAnimal(const WrongAnimal ©) : type(copy.type)
|
||||
{
|
||||
std::cout << CYAN << "WrongAnimal copy constructor called. Type is " << type << "." << RESET << std::endl;
|
||||
}
|
||||
|
||||
WrongAnimal& WrongAnimal::operator=(const WrongAnimal &operator_aff)
|
||||
{
|
||||
if (this != &operator_aff)
|
||||
{
|
||||
this->type = operator_aff.type;
|
||||
}
|
||||
std::cout << MAGENTA << "WrongAnimal assignment operator called. Type is now " << type << "." << RESET << std::endl;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
WrongAnimal::~WrongAnimal()
|
||||
{
|
||||
std::cout << RED << "WrongAnimal destructor called. Type was " << type << "." << RESET << std::endl;
|
||||
}
|
||||
|
||||
std::string WrongAnimal::getType() const
|
||||
{
|
||||
return (this->type);
|
||||
}
|
||||
|
||||
void WrongAnimal::makeSound() const
|
||||
{
|
||||
std::cout << "WrongAnimal makes a wrong sound!" << std::endl;
|
||||
}
|
||||
44
cpp04/ex00/WrongAnimal.hpp
Normal file
44
cpp04/ex00/WrongAnimal.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* WrongAnimal.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/31 12:19:34 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/31 12:55:37 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef WRONGANIMAL_HPP
|
||||
#define WRONGANIMAL_HPP
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#define RESET "\033[0m"
|
||||
#define BLACK "\033[30m"
|
||||
#define RED "\033[31m"
|
||||
#define GREEN "\033[32m"
|
||||
#define YELLOW "\033[33m"
|
||||
#define BLUE "\033[34m"
|
||||
#define MAGENTA "\033[35m"
|
||||
#define CYAN "\033[36m"
|
||||
#define WHITE "\033[37m"
|
||||
|
||||
class WrongAnimal
|
||||
{
|
||||
protected:
|
||||
std::string type;
|
||||
|
||||
public:
|
||||
WrongAnimal();
|
||||
WrongAnimal(const WrongAnimal ©);
|
||||
WrongAnimal& operator=(const WrongAnimal &operator_aff);
|
||||
~WrongAnimal();
|
||||
|
||||
std::string getType() const;
|
||||
void makeSound() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
41
cpp04/ex00/WrongCat.cpp
Normal file
41
cpp04/ex00/WrongCat.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* WrongCat.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/31 12:58:15 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/31 12:59:48 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "WrongCat.hpp"
|
||||
|
||||
WrongCat::WrongCat()
|
||||
{
|
||||
type = "WrongCat";
|
||||
std::cout << GREEN << "WrongCat default constructor called. Type is set to " << type << "." << RESET << std::endl;
|
||||
}
|
||||
|
||||
WrongCat::WrongCat(const WrongCat ©) : WrongAnimal(copy)
|
||||
{
|
||||
std::cout << CYAN << "WrongCat copy constructor called. Type is " << type << "." << RESET << std::endl;
|
||||
}
|
||||
|
||||
WrongCat& WrongCat::operator=(const WrongCat &operator_aff)
|
||||
{
|
||||
WrongAnimal::operator=(operator_aff);
|
||||
std::cout << MAGENTA << "WrongCat assignment operator called. Type is now " << type << "." << RESET << std::endl;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
WrongCat::~WrongCat()
|
||||
{
|
||||
std::cout << RED << "WrongCat destructor called. Type was " << type << "." << RESET << std::endl;
|
||||
}
|
||||
|
||||
void WrongCat::makeSound() const
|
||||
{
|
||||
std::cout << "WrongCat makes a wrong sound!" << std::endl;
|
||||
}
|
||||
29
cpp04/ex00/WrongCat.hpp
Normal file
29
cpp04/ex00/WrongCat.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* WrongCat.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/31 12:22:35 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/31 16:31:44 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef WRONGCAT_HPP
|
||||
#define WRONGCAT_HPP
|
||||
|
||||
#include "WrongAnimal.hpp"
|
||||
|
||||
class WrongCat : public WrongAnimal
|
||||
{
|
||||
public:
|
||||
WrongCat();
|
||||
WrongCat(const WrongCat ©);
|
||||
WrongCat& operator=(const WrongCat &operator_aff);
|
||||
~WrongCat();
|
||||
|
||||
void makeSound() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
62
cpp04/ex00/main.cpp
Normal file
62
cpp04/ex00/main.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/31 13:00:09 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/31 13:19:56 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Animal.hpp"
|
||||
#include "Dog.hpp"
|
||||
#include "Cat.hpp"
|
||||
#include "WrongAnimal.hpp"
|
||||
#include "WrongCat.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
const Animal* meta = new Animal();
|
||||
const Animal* j = new Dog();
|
||||
const Animal* i = new Cat();
|
||||
|
||||
std::cout << j->getType() << " " << std::endl;
|
||||
std::cout << i->getType() << " " << std::endl;
|
||||
i->makeSound();
|
||||
j->makeSound();
|
||||
meta->makeSound();
|
||||
|
||||
delete meta;
|
||||
delete j;
|
||||
delete i;
|
||||
|
||||
std::cout << "\n--- Tests WrongAnimal & WrongCat ---\n" << std::endl;
|
||||
|
||||
const WrongAnimal* wrongMeta = new WrongAnimal();
|
||||
const WrongAnimal* wrongCat = new WrongCat();
|
||||
|
||||
std::cout << wrongCat->getType() << " " << std::endl;
|
||||
wrongCat->makeSound();
|
||||
wrongMeta->makeSound();
|
||||
|
||||
delete wrongMeta;
|
||||
delete wrongCat;
|
||||
|
||||
std::cout << "\n--- Tests supplémentaires pour Dog & Cat ---\n" << std::endl;
|
||||
|
||||
Dog dog1, dog2;
|
||||
Cat cat1, cat2;
|
||||
|
||||
dog1.makeSound();
|
||||
cat1.makeSound();
|
||||
|
||||
Dog dog3(dog1);
|
||||
dog3.makeSound();
|
||||
|
||||
cat2 = cat1;
|
||||
cat2.makeSound();
|
||||
|
||||
return (0);
|
||||
}
|
||||
Reference in New Issue
Block a user