Animal class started
This commit is contained in:
25
ex00/Animal/Animal.cpp
Normal file
25
ex00/Animal/Animal.cpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Animal.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */
|
||||||
|
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "Animal.hpp"
|
||||||
|
|
||||||
|
Animal::Animal() : type("Animal")
|
||||||
|
{
|
||||||
|
std::cout << "Animal has been created" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Animal::~Animal()
|
||||||
|
{
|
||||||
|
std::cout << "Animal has been destroyed" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
28
ex00/Animal/Animal.hpp
Normal file
28
ex00/Animal/Animal.hpp
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Animal.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */
|
||||||
|
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef ANIMAL_HPP
|
||||||
|
|
||||||
|
# define ANIMAL_HPP
|
||||||
|
|
||||||
|
# include <iostream>
|
||||||
|
|
||||||
|
class Animal
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::string type;
|
||||||
|
public:
|
||||||
|
Animal();
|
||||||
|
~Animal();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
25
ex00/Makefile
Normal file
25
ex00/Makefile
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
NAME = animals
|
||||||
|
|
||||||
|
SRCS = main.cpp
|
||||||
|
OBJS = $(SRCS:.cpp=.o)
|
||||||
|
|
||||||
|
CC = cc
|
||||||
|
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(NAME): $(OBJS)
|
||||||
|
$(CC) $(CFLAGS) $(OBJS) -o $(NAME)
|
||||||
|
|
||||||
|
%.o: %cpp
|
||||||
|
$(CC) $(CFLAGS) -c $@ -o $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(OBJS)
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
rm -f $(NAME)
|
||||||
|
|
||||||
|
re: fclean all
|
||||||
|
|
||||||
|
.PHONY: all clean fclean re
|
||||||
29
ex00/main.cpp
Normal file
29
ex00/main.cpp
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hadi <hadi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/11/08 17:43:10 by hadi #+# #+# */
|
||||||
|
/* Updated: 2025/11/08 18:01:46 by hadi ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "Animal/Animal.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();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user