Compare commits

...

No commits in common. "master" and "main" have entirely different histories.
master ... main

44 changed files with 3 additions and 968 deletions

2
.gitignore vendored
View File

@ -1,2 +0,0 @@
ex0*/obj/*.o
ex0*/ex0*

1
ex00 Submodule

@ -0,0 +1 @@
Subproject commit c33eb0d88bf01995b0820717630b973b31fdd2e8

View File

@ -1,25 +0,0 @@
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
SRCDIR = src
OBJDIR = obj
NAME = ex00
SRCS = $(wildcard $(SRCDIR)/*.cpp)
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
all: $(NAME)
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
mkdir -p obj
$(CXX) $(CPPFLAGS) -c $< -o $@
$(NAME): $(OBJS)
$(CXX) $(CPPFLAGS) $^ -o $@
clean:
rm -rf $(OBJDIR)/*.o
fclean: clean
rm -fr $(NAME)
re: fclean all

View File

@ -1,34 +0,0 @@
#include "Animal.hpp"
#include <iostream>
#include <string>
Animal::Animal()
{
std::cout << "Animal()" << std::endl;
}
Animal::Animal(const Animal& src)
{
*this = src;
}
Animal& Animal::operator=(const Animal &src)
{
this->type = src.type;
return *this;
}
Animal::~Animal()
{
std::cout << "~Animal()" << std::endl;
}
void Animal::makeSound() const
{
std::cout << "OuGABounga" << std::endl;
}
std::string Animal::getType() const
{
return this->type;
}

View File

@ -1,19 +0,0 @@
#pragma once
#include <string>
class Animal
{
public:
Animal();
Animal(const Animal& src);
Animal &operator=(const Animal& src);
virtual ~Animal();
std::string getType() const;
virtual void makeSound() const;
protected:
std::string type;
};

View File

@ -1,30 +0,0 @@
#include "Cat.hpp"
#include "Animal.hpp"
#include <iostream>
Cat::Cat()
{
this->type = "Cat";
std::cout << "Cat()" << std::endl;
}
Cat& Cat::operator=(const Cat& src)
{
this->type = src.type;
return *this;
}
Cat::~Cat()
{
std::cout << "~Cat()" << std::endl;
}
Cat::Cat(const Cat& src): Animal()
{
*this = src;
}
void Cat::makeSound() const
{
std::cout << "Meow Meow !" << std::endl;
}

View File

@ -1,16 +0,0 @@
#pragma once
#include <string>
#include "./Animal.hpp"
class Cat : public Animal
{
public:
Cat(const Cat& src);
Cat &operator=(const Cat& src);
Cat();
~Cat();
void makeSound() const;
};

View File

@ -1,30 +0,0 @@
#include "Dog.hpp"
#include "Animal.hpp"
#include <iostream>
Dog::Dog()
{
this->type = "Dog";
std::cout << "Dog()" << std::endl;
}
Dog& Dog::operator=(const Dog& src)
{
this->type = src.type;
return *this;
}
Dog::~Dog()
{
std::cout << "~Dog()" << std::endl;
}
Dog::Dog(const Dog& src): Animal()
{
*this = src;
}
void Dog::makeSound() const
{
std::cout << "Ouaf ouaf !" << std::endl;
}

View File

@ -1,16 +0,0 @@
#pragma once
#include <string>
#include "./Animal.hpp"
class Dog : public Animal
{
public:
Dog(const Dog& src);
Dog &operator=(const Dog& src);
Dog();
~Dog();
void makeSound() const;
};

View File

@ -1,34 +0,0 @@
#include "WrongAnimal.hpp"
#include <iostream>
#include <string>
WrongAnimal::WrongAnimal()
{
std::cout << "WrongAnimal()" << std::endl;
}
WrongAnimal::WrongAnimal(const WrongAnimal& src)
{
*this = src;
}
WrongAnimal& WrongAnimal::operator=(const WrongAnimal &src)
{
this->type = src.type;
return *this;
}
WrongAnimal::~WrongAnimal()
{
std::cout << "~WrongAnimal()" << std::endl;
}
void WrongAnimal::makeSound() const
{
std::cout << "OuGABounga" << std::endl;
}
std::string WrongAnimal::getType() const
{
return this->type;
}

View File

@ -1,19 +0,0 @@
#pragma once
#include <string>
class WrongAnimal
{
public:
WrongAnimal();
WrongAnimal(const WrongAnimal& src);
WrongAnimal &operator=(const WrongAnimal& src);
virtual ~WrongAnimal();
std::string getType() const;
void makeSound() const;
protected:
std::string type;
};

View File

@ -1,24 +0,0 @@
#include "WrongCat.hpp"
#include <iostream>
WrongCat::WrongCat()
{
this->type = "WrongCat";
std::cout << "WrongCat()" << std::endl;
}
WrongCat& WrongCat::operator=(const WrongCat& src)
{
this->type = src.type;
return *this;
}
WrongCat::~WrongCat()
{
std::cout << "~WrongCat()" << std::endl;
}
WrongCat::WrongCat(const WrongCat& src): WrongAnimal()
{
*this = src;
}

View File

@ -1,14 +0,0 @@
#pragma once
#include <string>
#include "./WrongAnimal.hpp"
class WrongCat : public WrongAnimal
{
public:
WrongCat(const WrongCat& src);
WrongCat &operator=(const WrongCat& src);
WrongCat();
~WrongCat();
};

View File

@ -1,24 +0,0 @@
#include <iostream>
#include "Cat.hpp"
#include "Dog.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(); //will output the cat sound!
j->makeSound();
meta->makeSound();
delete meta;
delete j;
delete i;
const WrongCat* kitten = new WrongCat();
kitten->makeSound();
delete kitten;
return 0;
}

1
ex01 Submodule

@ -0,0 +1 @@
Subproject commit 3d8d2d2a0c74ee0458611f4344b1a5ac49cb9247

View File

@ -1,25 +0,0 @@
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
SRCDIR = src
OBJDIR = obj
NAME = ex01
SRCS = $(wildcard $(SRCDIR)/*.cpp)
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
all: $(NAME)
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
mkdir -p obj
$(CXX) $(CPPFLAGS) -c $< -o $@
$(NAME): $(OBJS)
$(CXX) $(CPPFLAGS) $^ -o $@
clean:
rm -rf $(OBJDIR)/*.o
fclean: clean
rm -fr $(NAME)
re: fclean all

View File

@ -1,34 +0,0 @@
#include "Animal.hpp"
#include <iostream>
#include <string>
Animal::Animal()
{
std::cout << "Animal()" << std::endl;
}
Animal::Animal(const Animal& src)
{
*this = src;
}
Animal& Animal::operator=(const Animal &src)
{
this->type = src.type;
return *this;
}
Animal::~Animal()
{
std::cout << "~Animal()" << std::endl;
}
void Animal::makeSound() const
{
std::cout << "OuGABounga" << std::endl;
}
std::string Animal::getType() const
{
return this->type;
}

View File

@ -1,19 +0,0 @@
#pragma once
#include <string>
class Animal
{
public:
Animal();
Animal(const Animal& src);
Animal &operator=(const Animal& src);
virtual ~Animal();
std::string getType() const;
virtual void makeSound() const;
protected:
std::string type;
};

View File

@ -1,24 +0,0 @@
#include "Brain.hpp"
#include <iostream>
Brain& Brain::operator=(const Brain &src)
{
for (size_t i = 0; i < 100; i++)
this->ideas[i] = src.ideas[i];
return *this;
}
Brain::~Brain()
{
std::cout << "~Brain()" << std::endl;
}
Brain::Brain()
{
std::cout << "Brain()" << std::endl;
}
Brain::Brain(const Brain& src)
{
*this = src;
}

View File

@ -1,14 +0,0 @@
#pragma once
#include <string>
class Brain
{
public:
Brain();
Brain(const Brain& src);
~Brain();
Brain& operator=(const Brain& src);
private:
std::string ideas[100];
};

View File

@ -1,33 +0,0 @@
#include "Cat.hpp"
#include <iostream>
Cat::Cat()
{
this->brain = new Brain();
this->type = "Cat";
std::cout << "Cat()" << std::endl;
}
Cat& Cat::operator=(const Cat& src)
{
*this->brain = *src.brain;
this->type = src.type;
return *this;
}
Cat::~Cat()
{
delete this->brain;
std::cout << "~Cat()" << std::endl;
}
Cat::Cat(const Cat& src): Animal()
{
this->brain = new Brain();
*this = src;
}
void Cat::makeSound() const
{
std::cout << "Meow Meow !" << std::endl;
}

View File

@ -1,20 +0,0 @@
#pragma once
#include <string>
#include "./Animal.hpp"
#include "./Brain.hpp"
class Cat : public Animal
{
public:
Cat(const Cat& src);
Cat &operator=(const Cat& src);
Cat();
~Cat();
void makeSound() const;
private:
Brain* brain;
};

View File

@ -1,34 +0,0 @@
#include "Dog.hpp"
#include <iostream>
Dog::Dog()
{
this->type = "Dog";
this->brain = new Brain();
std::cout << "Dog()" << std::endl;
}
Dog& Dog::operator=(const Dog& src)
{
*this->brain = *src.brain;
this->type = src.type;
return *this;
}
Dog::~Dog()
{
delete this->brain;
std::cout << "~Dog()" << std::endl;
}
Dog::Dog(const Dog& src): Animal()
{
this->brain = new Brain();
*this = src;
}
void Dog::makeSound() const
{
std::cout << "Ouaf ouaf !" << std::endl;
}

View File

@ -1,20 +0,0 @@
#pragma once
#include <string>
#include "./Animal.hpp"
#include "./Brain.hpp"
class Dog : public Animal
{
public:
Dog(const Dog& src);
Dog &operator=(const Dog& src);
Dog();
~Dog();
void makeSound() const;
private:
Brain* brain;
};

View File

@ -1,34 +0,0 @@
#include "WrongAnimal.hpp"
#include <iostream>
#include <string>
WrongAnimal::WrongAnimal()
{
std::cout << "WrongAnimal()" << std::endl;
}
WrongAnimal::WrongAnimal(const WrongAnimal& src)
{
*this = src;
}
WrongAnimal& WrongAnimal::operator=(const WrongAnimal &src)
{
this->type = src.type;
return *this;
}
WrongAnimal::~WrongAnimal()
{
std::cout << "~WrongAnimal()" << std::endl;
}
void WrongAnimal::makeSound() const
{
std::cout << "OuGABounga" << std::endl;
}
std::string WrongAnimal::getType() const
{
return this->type;
}

View File

@ -1,19 +0,0 @@
#pragma once
#include <string>
class WrongAnimal
{
public:
WrongAnimal();
WrongAnimal(const WrongAnimal& src);
WrongAnimal &operator=(const WrongAnimal& src);
virtual ~WrongAnimal();
std::string getType() const;
void makeSound() const;
protected:
std::string type;
};

View File

@ -1,29 +0,0 @@
#include "WrongCat.hpp"
#include <iostream>
WrongCat::WrongCat()
{
this->type = "WrongCat";
std::cout << "WrongCat()" << std::endl;
}
WrongCat& WrongCat::operator=(const WrongCat& src)
{
this->type = src.type;
return *this;
}
WrongCat::~WrongCat()
{
std::cout << "~WrongCat()" << std::endl;
}
WrongCat::WrongCat(const WrongCat& src): WrongAnimal()
{
*this = src;
}
void WrongCat::makeSound() const
{
std::cout << "Meow Meow !" << std::endl;
}

View File

@ -1,16 +0,0 @@
#pragma once
#include <string>
#include "./WrongAnimal.hpp"
class WrongCat : public WrongAnimal
{
public:
WrongCat(const WrongCat& src);
WrongCat &operator=(const WrongCat& src);
WrongCat();
~WrongCat();
void makeSound() const;
};

View File

@ -1,24 +0,0 @@
#include <iostream>
#include "Cat.hpp"
#include "Dog.hpp"
#include "WrongAnimal.hpp"
#include "WrongCat.hpp"
int main()
{
const Animal* meta = new Animal();
delete meta;
const Animal* j = new Dog();
delete j;
const Animal* i = new Cat();
delete i;
const WrongAnimal* k = new WrongCat();
k->makeSound();
Dog test;
{
Dog test2 = test;
}
delete k;
return 0;
}

1
ex02 Submodule

@ -0,0 +1 @@
Subproject commit faba8248df315d1cf1487081fab253d57aab377c

View File

@ -1,25 +0,0 @@
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
SRCDIR = src
OBJDIR = obj
NAME = ex02
SRCS = $(wildcard $(SRCDIR)/*.cpp)
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
all: $(NAME)
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
mkdir -p obj
$(CXX) $(CPPFLAGS) -c $< -o $@
$(NAME): $(OBJS)
$(CXX) $(CPPFLAGS) $^ -o $@
clean:
rm -rf $(OBJDIR)/*.o
fclean: clean
rm -fr $(NAME)
re: fclean all

View File

@ -1,29 +0,0 @@
#include "AAnimal.hpp"
#include <iostream>
#include <string>
AAnimal::AAnimal()
{
std::cout << "AAnimal()" << std::endl;
}
AAnimal::AAnimal(const AAnimal& src)
{
*this = src;
}
AAnimal& AAnimal::operator=(const AAnimal &src)
{
this->type = src.type;
return *this;
}
AAnimal::~AAnimal()
{
std::cout << "~AAnimal()" << std::endl;
}
std::string AAnimal::getType() const
{
return this->type;
}

View File

@ -1,19 +0,0 @@
#pragma once
#include <string>
class AAnimal
{
public:
AAnimal();
AAnimal(const AAnimal& src);
AAnimal &operator=(const AAnimal& src);
virtual ~AAnimal();
std::string getType() const;
virtual void makeSound() const = 0;
protected:
std::string type;
};

View File

@ -1,24 +0,0 @@
#include "Brain.hpp"
#include <iostream>
Brain& Brain::operator=(const Brain &src)
{
for (size_t i = 0; i < 100; i++)
this->ideas[i] = src.ideas[i];
return *this;
}
Brain::~Brain()
{
std::cout << "~Brain()" << std::endl;
}
Brain::Brain()
{
std::cout << "Brain()" << std::endl;
}
Brain::Brain(const Brain& src)
{
*this = src;
}

View File

@ -1,14 +0,0 @@
#pragma once
#include <string>
class Brain
{
public:
Brain();
Brain(const Brain& src);
~Brain();
Brain& operator=(const Brain& src);
private:
std::string ideas[100];
};

View File

@ -1,33 +0,0 @@
#include "Cat.hpp"
#include <iostream>
Cat::Cat()
{
this->brain = new Brain();
this->type = "Cat";
std::cout << "Cat()" << std::endl;
}
Cat& Cat::operator=(const Cat& src)
{
*this->brain = *src.brain;
this->type = src.type;
return *this;
}
Cat::~Cat()
{
delete this->brain;
std::cout << "~Cat()" << std::endl;
}
Cat::Cat(const Cat& src): AAnimal()
{
this->brain = new Brain();
*this = src;
}
void Cat::makeSound() const
{
std::cout << "Meow Meow !" << std::endl;
}

View File

@ -1,20 +0,0 @@
#pragma once
#include <string>
#include "./AAnimal.hpp"
#include "./Brain.hpp"
class Cat : public AAnimal
{
public:
Cat(const Cat& src);
Cat &operator=(const Cat& src);
Cat();
~Cat();
void makeSound() const;
private:
Brain* brain;
};

View File

@ -1,34 +0,0 @@
#include "Dog.hpp"
#include <iostream>
Dog::Dog()
{
this->type = "Dog";
this->brain = new Brain();
std::cout << "Dog()" << std::endl;
}
Dog& Dog::operator=(const Dog& src)
{
*this->brain = *src.brain;
this->type = src.type;
return *this;
}
Dog::~Dog()
{
delete this->brain;
std::cout << "~Dog()" << std::endl;
}
Dog::Dog(const Dog& src): AAnimal()
{
this->brain = new Brain();
*this = src;
}
void Dog::makeSound() const
{
std::cout << "Ouaf ouaf !" << std::endl;
}

View File

@ -1,20 +0,0 @@
#pragma once
#include <string>
#include "./AAnimal.hpp"
#include "./Brain.hpp"
class Dog : public AAnimal
{
public:
Dog(const Dog& src);
Dog &operator=(const Dog& src);
Dog();
~Dog();
void makeSound() const;
private:
Brain* brain;
};

View File

@ -1,34 +0,0 @@
#include "WrongAnimal.hpp"
#include <iostream>
#include <string>
WrongAnimal::WrongAnimal()
{
std::cout << "WrongAnimal()" << std::endl;
}
WrongAnimal::WrongAnimal(const WrongAnimal& src)
{
*this = src;
}
WrongAnimal& WrongAnimal::operator=(const WrongAnimal &src)
{
this->type = src.type;
return *this;
}
WrongAnimal::~WrongAnimal()
{
std::cout << "~WrongAnimal()" << std::endl;
}
void WrongAnimal::makeSound() const
{
std::cout << "OuGABounga" << std::endl;
}
std::string WrongAnimal::getType() const
{
return this->type;
}

View File

@ -1,19 +0,0 @@
#pragma once
#include <string>
class WrongAnimal
{
public:
WrongAnimal();
WrongAnimal(const WrongAnimal& src);
WrongAnimal &operator=(const WrongAnimal& src);
virtual ~WrongAnimal();
std::string getType() const;
void makeSound() const;
protected:
std::string type;
};

View File

@ -1,29 +0,0 @@
#include "WrongCat.hpp"
#include <iostream>
WrongCat::WrongCat()
{
this->type = "WrongCat";
std::cout << "WrongCat()" << std::endl;
}
WrongCat& WrongCat::operator=(const WrongCat& src)
{
this->type = src.type;
return *this;
}
WrongCat::~WrongCat()
{
std::cout << "~WrongCat()" << std::endl;
}
WrongCat::WrongCat(const WrongCat& src): WrongAnimal()
{
*this = src;
}
void WrongCat::makeSound() const
{
std::cout << "Meow Meow !" << std::endl;
}

View File

@ -1,16 +0,0 @@
#pragma once
#include <string>
#include "./WrongAnimal.hpp"
class WrongCat : public WrongAnimal
{
public:
WrongCat(const WrongCat& src);
WrongCat &operator=(const WrongCat& src);
WrongCat();
~WrongCat();
void makeSound() const;
};

View File

@ -1,20 +0,0 @@
#include <iostream>
#include "AAnimal.hpp"
#include "Cat.hpp"
#include "Dog.hpp"
#include "WrongCat.hpp"
int main()
{
const AAnimal* j = new Dog();
delete j;
const AAnimal* i = new Cat();
delete i;
Dog test;
{
Dog test2 = test;
}
//const AAnimal* meta = new AAnimal();
return 0;
}