diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-12-15 11:39:36 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-12-15 11:39:36 +0100 |
| commit | 78efa932fb42289904fe542cfc152978397ae37c (patch) | |
| tree | 6878dc28e015f570aa6951f1d781115551d03997 /cpp07/ex00 | |
| parent | 1de596dd9242b677d6b47b51db98ce98feb95465 (diff) | |
| download | piscine_cpp-78efa932fb42289904fe542cfc152978397ae37c.tar.gz piscine_cpp-78efa932fb42289904fe542cfc152978397ae37c.tar.bz2 piscine_cpp-78efa932fb42289904fe542cfc152978397ae37c.zip | |
Fixing cpp07/ex00 with const& & and type only, Added more test in main for cpp07
Diffstat (limited to 'cpp07/ex00')
| -rw-r--r-- | cpp07/ex00/main.cpp | 28 | ||||
| -rw-r--r-- | cpp07/ex00/whatever.hpp | 25 |
2 files changed, 50 insertions, 3 deletions
diff --git a/cpp07/ex00/main.cpp b/cpp07/ex00/main.cpp index 1c04faf..26ec956 100644 --- a/cpp07/ex00/main.cpp +++ b/cpp07/ex00/main.cpp @@ -6,7 +6,7 @@ /* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/12/14 14:41:39 by cacharle #+# #+# */ -/* Updated: 2020/12/14 15:05:32 by cacharle ### ########.fr */ +/* Updated: 2020/12/15 11:10:07 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,23 @@ #include <string> #include "whatever.hpp" +NotAnInt::NotAnInt() : m_n(0) {} +NotAnInt::NotAnInt(int n) : m_n(n) {} +NotAnInt::NotAnInt(NotAnInt const& other) : m_n(other.m_n) {} +NotAnInt& NotAnInt::operator=(NotAnInt const& other) { m_n = other.m_n; return *this; } + +bool NotAnInt::operator==(NotAnInt const& other) const { return m_n == other.m_n; } +bool NotAnInt::operator!=(NotAnInt const& other) const { return m_n != other.m_n; } +bool NotAnInt::operator>(NotAnInt const& other) const { return m_n > other.m_n; } +bool NotAnInt::operator<(NotAnInt const& other) const { return m_n < other.m_n; } +bool NotAnInt::operator>=(NotAnInt const& other) const { return m_n >= other.m_n; } +bool NotAnInt::operator<=(NotAnInt const& other) const { return m_n <= other.m_n; } + +int NotAnInt::getN() const { return m_n; } + +std::ostream& operator<<(std::ostream& out, NotAnInt const& n) { out << n.getN(); return out; } + + int main() { { @@ -41,6 +58,8 @@ int main() float bf = 4.5f; char ac = 'a'; char bc = 'b'; + NotAnInt ai(34); + NotAnInt bi(43); std::cout << "=================== SWAP ================" << std::endl; ::swap(af, bf); std::cout << "af = " << af << ", bf = " << bf << std::endl; @@ -48,6 +67,8 @@ int main() std::cout << "ad = " << ad << ", bd = " << bd << std::endl; ::swap(ac, bc); std::cout << "ac = " << ac << ", bc = " << bc << std::endl; + ::swap(ai, bi); + std::cout << "ai = " << ai << ", bi = " << bi << std::endl; } std::cout << std::endl; @@ -58,7 +79,8 @@ int main() float bf = 4.5f; char ac = 'a'; char bc = 'b'; - + NotAnInt ai(54); + NotAnInt bi(53); int same1 = 4; int same2 = 4; @@ -67,6 +89,7 @@ int main() std::cout << "min(af, bf) = " << ::min(af, bf) << std::endl; std::cout << "min(ad, bd) = " << ::min(ad, bd) << std::endl; std::cout << "min(ac, bc) = " << ::min(ac, bc) << std::endl; + std::cout << "min(ai, bi) = " << ::min(ai, bi) << std::endl; int &minsame = ::min(same1, same2); std::cout << "min(same1, same2) = " << minsame << ", address same2 = " << &same2 << ", address minsame = " << &minsame << std::endl; @@ -76,6 +99,7 @@ int main() std::cout << "max(af, bf) = " << ::max(af, bf) << std::endl; std::cout << "max(ad, bd) = " << ::max(ad, bd) << std::endl; std::cout << "max(ac, bc) = " << ::max(ac, bc) << std::endl; + std::cout << "max(ai, bi) = " << ::max(ai, bi) << std::endl; int &maxsame = ::max(same1, same2); std::cout << "max(same1, same2) = " << maxsame << ", address same2 = " << &same2 << ", address maxsame = " << &maxsame << std::endl; diff --git a/cpp07/ex00/whatever.hpp b/cpp07/ex00/whatever.hpp index 8768a44..53953f8 100644 --- a/cpp07/ex00/whatever.hpp +++ b/cpp07/ex00/whatever.hpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 19:46:56 by charles #+# #+# */ -/* Updated: 2020/12/14 15:05:32 by cacharle ### ########.fr */ +/* Updated: 2020/12/15 11:08:51 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,4 +33,27 @@ T& max(T& a, T& b) return a > b ? a : b; } +class NotAnInt +{ +public: + NotAnInt(); + NotAnInt(int n); + NotAnInt(NotAnInt const& other); + NotAnInt& operator=(NotAnInt const& other); + + bool operator==(NotAnInt const& other) const; + bool operator!=(NotAnInt const& other) const; + bool operator>(NotAnInt const& other) const; + bool operator<(NotAnInt const& other) const; + bool operator>=(NotAnInt const& other) const; + bool operator<=(NotAnInt const& other) const; + + int getN() const; + +private: + int m_n; +}; + +std::ostream& operator<<(std::ostream& out, NotAnInt const& n); + #endif |
