From: Lukas Jiriste Date: Thu, 17 Oct 2024 07:37:00 +0000 (+0200) Subject: Implement solution to ex00 (without Makefile) X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=cda271bbd455b4b788afd481fc1eb4d117c156fb;p=42%2FCPP_Module_02 Implement solution to ex00 (without Makefile) --- cda271bbd455b4b788afd481fc1eb4d117c156fb 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