aboutsummaryrefslogtreecommitdiff
path: root/cpp04/ex00
diff options
context:
space:
mode:
Diffstat (limited to 'cpp04/ex00')
-rw-r--r--cpp04/ex00/Peon.cpp15
-rw-r--r--cpp04/ex00/Peon.hpp6
-rw-r--r--cpp04/ex00/Sorcerer.cpp38
-rw-r--r--cpp04/ex00/Sorcerer.hpp10
-rw-r--r--cpp04/ex00/Victim.cpp28
-rw-r--r--cpp04/ex00/Victim.hpp8
-rw-r--r--cpp04/ex00/main.cpp53
7 files changed, 87 insertions, 71 deletions
diff --git a/cpp04/ex00/Peon.cpp b/cpp04/ex00/Peon.cpp
index df55b4f..8388dc9 100644
--- a/cpp04/ex00/Peon.cpp
+++ b/cpp04/ex00/Peon.cpp
@@ -6,27 +6,24 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 20:53:16 by charles #+# #+# */
-/* Updated: 2020/04/13 21:00:23 by charles ### ########.fr */
+/* Updated: 2020/11/12 13:01:42 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "Peon.hpp"
-Peon::Peon(std::string name):
- Victim(name)
+Peon::Peon(std::string const& name) : Victim(name)
{
std::cout << "Zog zog." << std::endl;
}
-void Peon::operator=(Peon const& other)
+Peon& Peon::operator=(Peon const& other)
{
- m_name = other.m_name;
+ Victim::operator=(other);
+ return *this;
}
-Peon::Peon(Peon const& other)
- : Victim(other)
-{
-}
+Peon::Peon(Peon const& other) : Victim(other) {}
Peon::~Peon()
{
diff --git a/cpp04/ex00/Peon.hpp b/cpp04/ex00/Peon.hpp
index 2d57a05..0f50207 100644
--- a/cpp04/ex00/Peon.hpp
+++ b/cpp04/ex00/Peon.hpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 20:50:54 by charles #+# #+# */
-/* Updated: 2020/04/13 20:57:37 by charles ### ########.fr */
+/* Updated: 2020/11/12 13:00:49 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,8 +20,8 @@
class Peon : public Victim
{
public:
- Peon(std::string name);
- void operator=(Peon const& other);
+ Peon(std::string const& name);
+ Peon& operator=(Peon const& other);
Peon(Peon const& other);
~Peon();
diff --git a/cpp04/ex00/Sorcerer.cpp b/cpp04/ex00/Sorcerer.cpp
index c6910ce..c3d0999 100644
--- a/cpp04/ex00/Sorcerer.cpp
+++ b/cpp04/ex00/Sorcerer.cpp
@@ -6,54 +6,40 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 20:29:19 by charles #+# #+# */
-/* Updated: 2020/04/13 20:49:48 by charles ### ########.fr */
+/* Updated: 2020/11/12 12:55:36 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "Sorcerer.hpp"
-Sorcerer::Sorcerer(std::string name, std::string title):
+Sorcerer::Sorcerer(std::string const& name, std::string const& title) :
m_name(name),
m_title(title)
{
std::cout << name << ", " << title << ", is born!" << std::endl;
}
-void Sorcerer::operator=(Sorcerer const& other)
+Sorcerer& Sorcerer::operator=(Sorcerer const& other)
{
- m_name = other.m_name;
+ m_name = other.m_name;
m_title = other.m_title;
+ return *this;
}
-Sorcerer::Sorcerer(Sorcerer const& other)
-{
- *this = other;
-}
+Sorcerer::Sorcerer(Sorcerer const& other) { *this = other; }
Sorcerer::~Sorcerer()
{
std::cout << m_name << ", " << m_title
- << ", is dead. Consequences will never be the same!" << std::endl;
-}
-
-std::string const& Sorcerer::getName() const
-{
- return m_name;
-}
-
-std::string const& Sorcerer::getTitle() const
-{
- return m_title;
+ << ", is dead. Consequences will never be the same!"
+ << std::endl;
}
-void Sorcerer::polymorph(Victim const& v) const
-{
- v.getPolymorphed();
-}
+std::string const& Sorcerer::getName() const { return m_name; }
+std::string const& Sorcerer::getTitle() const { return m_title; }
+void Sorcerer::polymorph(Victim const& v) const { v.getPolymorphed(); }
-Sorcerer::Sorcerer()
-{
-}
+Sorcerer::Sorcerer() {}
std::ostream& operator<<(std::ostream& out, Sorcerer const& s)
{
diff --git a/cpp04/ex00/Sorcerer.hpp b/cpp04/ex00/Sorcerer.hpp
index ed261ae..cf7676b 100644
--- a/cpp04/ex00/Sorcerer.hpp
+++ b/cpp04/ex00/Sorcerer.hpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 20:27:26 by charles #+# #+# */
-/* Updated: 2020/04/13 20:58:46 by charles ### ########.fr */
+/* Updated: 2020/11/12 12:51:45 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,13 +20,13 @@
class Sorcerer
{
public:
- Sorcerer(std::string name, std::string title);
- void operator=(Sorcerer const& other);
+ Sorcerer(std::string const& name, std::string const& title);
+ Sorcerer& operator=(Sorcerer const& other);
Sorcerer(Sorcerer const& other);
~Sorcerer();
- std::string const& getName() const;
- std::string const& getTitle() const;
+ std::string const& getName() const;
+ std::string const& getTitle() const;
void polymorph(Victim const& v) const;
private:
diff --git a/cpp04/ex00/Victim.cpp b/cpp04/ex00/Victim.cpp
index 2f2f6ad..97db6ff 100644
--- a/cpp04/ex00/Victim.cpp
+++ b/cpp04/ex00/Victim.cpp
@@ -6,46 +6,40 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 20:42:22 by charles #+# #+# */
-/* Updated: 2020/04/13 20:59:51 by charles ### ########.fr */
+/* Updated: 2020/11/12 12:59:36 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "Victim.hpp"
-Victim::Victim(std::string name) :
- m_name(name)
+Victim::Victim(std::string const& name) : m_name(name)
{
- std::cout << "Some random victim called " << name << " just appeared!" << std::endl;
+ std::cout << "Some random victim called " << name
+ << " just appeared!" << std::endl;
}
-void Victim::operator=(Victim const& other)
+Victim& Victim::operator=(Victim const& other)
{
m_name = other.m_name;
+ return *this;
}
-Victim::Victim(Victim const& other)
-{
- *this = other;
-}
+Victim::Victim(Victim const& other) { *this = other; }
Victim::~Victim()
{
- std::cout << "Victim " << m_name << " just died for no apparent reason!" << std::endl;
+ std::cout << "Victim " << m_name
+ << " just died for no apparent reason!" << std::endl;
}
-std::string const& Victim::getName() const
-{
- return m_name;
-}
+std::string const& Victim::getName() const { return m_name; }
void Victim::getPolymorphed() const
{
std::cout << m_name << " has been turned into a cute little sheep!" << std::endl;
}
-Victim::Victim()
-{
-}
+Victim::Victim() {}
std::ostream& operator<<(std::ostream& out, Victim const& v)
{
diff --git a/cpp04/ex00/Victim.hpp b/cpp04/ex00/Victim.hpp
index dafd8c6..bf2b467 100644
--- a/cpp04/ex00/Victim.hpp
+++ b/cpp04/ex00/Victim.hpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 20:40:50 by charles #+# #+# */
-/* Updated: 2020/04/13 20:59:08 by charles ### ########.fr */
+/* Updated: 2020/11/12 12:57:01 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,12 +19,12 @@
class Victim
{
public:
- Victim(std::string name);
- void operator=(Victim const& other);
+ Victim(std::string const& name);
+ Victim& operator=(Victim const& other);
Victim(Victim const& other);
~Victim();
- std::string const& getName() const;
+ std::string const& getName() const;
virtual void getPolymorphed() const;
protected:
diff --git a/cpp04/ex00/main.cpp b/cpp04/ex00/main.cpp
index 9c17e99..8bf96bf 100644
--- a/cpp04/ex00/main.cpp
+++ b/cpp04/ex00/main.cpp
@@ -6,25 +6,64 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 20:47:34 by charles #+# #+# */
-/* Updated: 2020/04/13 20:57:19 by charles ### ########.fr */
+/* Updated: 2020/11/12 13:11:26 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
+#include <iostream>
#include "Sorcerer.hpp"
#include "Victim.hpp"
#include "Peon.hpp"
int main()
{
- Sorcerer robert("Robert", "the Magnificent");
+ {
+ std::cout << "==================== SUBJECT MAIN =====================" << std::endl;
+ Sorcerer robert("Robert", "the Magnificent");
+ Victim jim("Jimmy");
+ Peon joe("Joe");
+ std::cout << robert << jim << joe;
+ robert.polymorph(jim);
+ robert.polymorph(joe);
+ }
- Victim jim("Jimmy");
- Peon joe("Joe");
+ std::cout << std::endl;
- std::cout << robert << jim << joe;
+ {
+ std::cout << "==================== SORCERER =====================" << std::endl;
+ Sorcerer s("DidierLeSorcier", "The cunt");
+ Sorcerer s_copied(s);
+ Sorcerer s_assigned("foo", "yep clock");
+ s_assigned = s;
+ std::cout << "Copied: " << s_copied;
+ std::cout << "Assigned: " << s_assigned;
+ }
- robert.polymorph(jim);
- robert.polymorph(joe);
+ std::cout << std::endl;
+
+ {
+ std::cout << "==================== VICTIM =====================" << std::endl;
+ Victim v("Victoire");
+ Victim v_copied(v);
+ Victim v_assigned("bar");
+ v_assigned = v;
+ std::cout << "Copied: " << v_copied;
+ std::cout << "Assigned: " << v_assigned;
+ v.getPolymorphed();
+ }
+
+ std::cout << std::endl;
+
+ {
+ std::cout << "==================== PEON =====================" << std::endl;
+ Peon p("Victoire");
+ Peon p_copied(p);
+ Peon p_assigned("baz");
+ p_assigned = p;
+ std::cout << "Copied: " << p_copied;
+ std::cout << "Assigned: " << p_assigned;
+ p.getPolymorphed();
+ }
return 0;
}