From cda271bbd455b4b788afd481fc1eb4d117c156fb Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Thu, 17 Oct 2024 09:37:00 +0200 Subject: [PATCH 1/1] Implement solution to ex00 (without Makefile) --- ex00/Fixed.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ ex00/Fixed.h | 20 ++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 ex00/Fixed.cpp create mode 100644 ex00/Fixed.h diff --git a/ex00/Fixed.cpp b/ex00/Fixed.cpp new file mode 100644 index 0000000..63539e0 --- /dev/null +++ b/ex00/Fixed.cpp @@ -0,0 +1,40 @@ +#include "Fixed.h" +#include + +Fixed::Fixed(): m_num(0) +{ + std::cout << "Default constructor called\n"; +} + +Fixed::Fixed(const Fixed &other) +{ + std::cout << "Copy constructor called\n"; + *this = other; +} + +Fixed::~Fixed() +{ + std::cout << "Destructor called\n"; +} + +Fixed &Fixed::operator=(const Fixed &other) +{ + std::cout << "Copy assignment operator called\n"; + if (this == &other) + return (*this); + m_num = other.getRawBits(); + return (*this); +} + +int Fixed::getRawBits() const +{ + std::cout << "getRawBits member function called\n"; + return (m_num); +} + +void Fixed::setRawBits(int const raw) +{ + std::cout << "setRawBits member function called\n"; + m_num = raw; +} + diff --git a/ex00/Fixed.h b/ex00/Fixed.h new file mode 100644 index 0000000..3638837 --- /dev/null +++ b/ex00/Fixed.h @@ -0,0 +1,20 @@ +#ifndef FIXED_H +# define FIXED_H + +class Fixed +{ + private: + static const int point_pos = 8; + int m_num; + + public: + Fixed(); + Fixed(const Fixed &other); + ~Fixed(); + + Fixed &operator=(const Fixed &other); + int getRawBits() const; + void setRawBits(int const raw); +}; + +#endif // FIXED_H -- 2.30.2