diff options
Diffstat (limited to 'cpp04/ex00')
| -rw-r--r-- | cpp04/ex00/Peon.cpp | 35 | ||||
| -rw-r--r-- | cpp04/ex00/Peon.hpp | 18 | ||||
| -rw-r--r-- | cpp04/ex00/Sorcerer.cpp | 8 | ||||
| -rw-r--r-- | cpp04/ex00/Victim.cpp | 9 | ||||
| -rw-r--r-- | cpp04/ex00/Victim.hpp | 4 | ||||
| -rw-r--r-- | cpp04/ex00/main.cpp | 36 |
6 files changed, 98 insertions, 12 deletions
diff --git a/cpp04/ex00/Peon.cpp b/cpp04/ex00/Peon.cpp index 8388dc9..a3c2b4e 100644 --- a/cpp04/ex00/Peon.cpp +++ b/cpp04/ex00/Peon.cpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/13 20:53:16 by charles #+# #+# */ -/* Updated: 2020/11/12 13:01:42 by cacharle ### ########.fr */ +/* Updated: 2020/12/11 10:17:35 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,10 @@ Peon& Peon::operator=(Peon const& other) return *this; } -Peon::Peon(Peon const& other) : Victim(other) {} +Peon::Peon(Peon const& other) : Victim(other) +{ + std::cout << "Zog zog." << std::endl; +} Peon::~Peon() { @@ -34,3 +37,31 @@ void Peon::getPolymorphed() const { std::cout << m_name << " has been turned into a pink pony!" << std::endl; } + +/************************************************************************************/ + +Rat::Rat(std::string const& name) : Victim(name) +{ + std::cout << "Rats rats, everywhere you look, everywhere you turn there is rats." << std::endl; +} + +Rat& Rat::operator=(Rat const& other) +{ + Victim::operator=(other); + return *this; +} + +Rat::Rat(Rat const& other) : Victim(other) +{ + std::cout << "Rats rats, everywhere you look, everywhere you turn there is rats." << std::endl; +} + +Rat::~Rat() +{ + std::cout << "I'll stop runing everything now" << std::endl; +} + +void Rat::getPolymorphed() const +{ + std::cout << m_name << " has been turned into Ninja" << std::endl; +} diff --git a/cpp04/ex00/Peon.hpp b/cpp04/ex00/Peon.hpp index 0f50207..7fe1e6b 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/11/12 13:00:49 by cacharle ### ########.fr */ +/* Updated: 2020/12/11 10:26:58 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,7 @@ public: Peon(std::string const& name); Peon& operator=(Peon const& other); Peon(Peon const& other); - ~Peon(); + virtual ~Peon(); virtual void getPolymorphed() const; @@ -31,4 +31,18 @@ private: Peon(); }; +class Rat : public Victim +{ +public: + Rat(std::string const& name); + Rat& operator=(Rat const& other); + Rat(Rat const& other); + virtual ~Rat(); + + virtual void getPolymorphed() const; + +private: + Rat(); +}; + #endif diff --git a/cpp04/ex00/Sorcerer.cpp b/cpp04/ex00/Sorcerer.cpp index 21c313b..8fab8e3 100644 --- a/cpp04/ex00/Sorcerer.cpp +++ b/cpp04/ex00/Sorcerer.cpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/13 20:29:19 by charles #+# #+# */ -/* Updated: 2020/11/17 08:45:02 by cacharle ### ########.fr */ +/* Updated: 2020/12/11 10:15:40 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,11 @@ Sorcerer& Sorcerer::operator=(Sorcerer const& other) return *this; } -Sorcerer::Sorcerer(Sorcerer const& other) { *this = other; } +Sorcerer::Sorcerer(Sorcerer const& other) +{ + *this = other; + std::cout << m_name << ", " << m_title << ", is born!" << std::endl; +} Sorcerer::~Sorcerer() { diff --git a/cpp04/ex00/Victim.cpp b/cpp04/ex00/Victim.cpp index 97db6ff..ea11c6b 100644 --- a/cpp04/ex00/Victim.cpp +++ b/cpp04/ex00/Victim.cpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/13 20:42:22 by charles #+# #+# */ -/* Updated: 2020/11/12 12:59:36 by cacharle ### ########.fr */ +/* Updated: 2020/12/11 10:15:55 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,12 @@ Victim& Victim::operator=(Victim const& other) return *this; } -Victim::Victim(Victim const& other) { *this = other; } +Victim::Victim(Victim const& other) +{ + *this = other; + std::cout << "Some random victim called " << m_name + << " just appeared!" << std::endl; +} Victim::~Victim() { diff --git a/cpp04/ex00/Victim.hpp b/cpp04/ex00/Victim.hpp index bf2b467..f7c4218 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/11/12 12:57:01 by cacharle ### ########.fr */ +/* Updated: 2020/12/11 10:26:56 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ public: Victim(std::string const& name); Victim& operator=(Victim const& other); Victim(Victim const& other); - ~Victim(); + virtual ~Victim(); std::string const& getName() const; virtual void getPolymorphed() const; diff --git a/cpp04/ex00/main.cpp b/cpp04/ex00/main.cpp index d8eb897..f585dab 100644 --- a/cpp04/ex00/main.cpp +++ b/cpp04/ex00/main.cpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/13 20:47:34 by charles #+# #+# */ -/* Updated: 2020/11/17 08:42:34 by cacharle ### ########.fr */ +/* Updated: 2020/12/11 10:29:53 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,6 +35,10 @@ int main() Sorcerer s_copied(s); Sorcerer s_assigned("foo", "yep clock"); s_assigned = s; + Sorcerer *s_ptr = new Sorcerer("Foo", "Bar"); + std::cout << *s_ptr; + s_ptr->polymorph(Peon("Yep")); + delete s_ptr; std::cout << "Copied: " << s_copied; std::cout << "Assigned: " << s_assigned; } @@ -47,6 +51,10 @@ int main() Victim v_copied(v); Victim v_assigned("bar"); v_assigned = v; + Victim *v_ptr = new Victim("Foo"); + std::cout << *v_ptr; + v_ptr->getPolymorphed(); + delete v_ptr; std::cout << "Copied: " << v_copied; std::cout << "Assigned: " << v_assigned; v.getPolymorphed(); @@ -56,14 +64,38 @@ int main() { std::cout << "==================== PEON =====================" << std::endl; - Peon p("Victoire"); + Peon p("Pionnier"); Peon p_copied(p); Peon p_assigned("baz"); p_assigned = p; + Peon *p_ptr = new Peon("Foo"); + std::cout << *p_ptr; + p_ptr->getPolymorphed(); + delete p_ptr; std::cout << "Copied: " << p_copied; std::cout << "Assigned: " << p_assigned; p.getPolymorphed(); } + std::cout << std::endl; + + { + std::cout << "==================== RAT =====================" << std::endl; + Rat r("Ratteur"); + std::cout << r; + Rat r_copied(r); + Rat r_assigned("baz"); + r_assigned = r; + Rat *r_ptr = new Rat("Foo"); + std::cout << *r_ptr; + r_ptr->getPolymorphed(); + delete r_ptr; + std::cout << "Copied: " << r_copied; + std::cout << "Assigned: " << r_assigned; + r.getPolymorphed(); + Sorcerer s("Sorcier", "Yes man"); + s.polymorph(r); + } + return 0; } |
