diff options
Diffstat (limited to 'cpp02/ex00')
| -rw-r--r-- | cpp02/ex00/Fixed.cpp | 48 | ||||
| -rw-r--r-- | cpp02/ex00/Fixed.hpp | 33 | ||||
| -rw-r--r-- | cpp02/ex00/main.cpp | 27 |
3 files changed, 108 insertions, 0 deletions
diff --git a/cpp02/ex00/Fixed.cpp b/cpp02/ex00/Fixed.cpp index e69de29..eb0501b 100644 --- a/cpp02/ex00/Fixed.cpp +++ b/cpp02/ex00/Fixed.cpp @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Fixed.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/13 11:45:18 by charles #+# #+# */ +/* Updated: 2020/04/13 11:58:37 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Fixed.hpp" + +Fixed::Fixed() + : m_value(0) +{ + std::cout << "Default constructor called" << std::endl; +} + +Fixed::Fixed(Fixed const& other) +{ + std::cout << "Copy constructor called" << std::endl; + *this = other; +} + +Fixed::~Fixed() +{ + std::cout << "Destructor called" << std::endl; +} + +void Fixed::operator=(Fixed const& other) +{ + std::cout << "Assignation operator called" << std::endl; + m_value = other.getRawBits(); +} + +int Fixed::getRawBits() const +{ + std::cout << "getRawBits member function called" << std::endl; + return m_value; +} + +void Fixed::setRawBits(int const raw) +{ + std::cout << "setRawBits member function called" << std::endl; + m_value = raw; +} diff --git a/cpp02/ex00/Fixed.hpp b/cpp02/ex00/Fixed.hpp index e69de29..1f956d7 100644 --- a/cpp02/ex00/Fixed.hpp +++ b/cpp02/ex00/Fixed.hpp @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Fixed.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/13 11:40:49 by charles #+# #+# */ +/* Updated: 2020/04/13 11:53:30 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FIXED_HPP +# define FIXED_HPP + +# include <iostream> + +class Fixed +{ +public: + Fixed(); + Fixed(Fixed const& other); + ~Fixed(); + void operator=(Fixed const& other); + int getRawBits() const; + void setRawBits(int const raw); + +private: + int m_value; + static int const m_fractional_bits = 8; +}; + +#endif diff --git a/cpp02/ex00/main.cpp b/cpp02/ex00/main.cpp new file mode 100644 index 0000000..494dbb3 --- /dev/null +++ b/cpp02/ex00/main.cpp @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/13 11:51:15 by charles #+# #+# */ +/* Updated: 2020/04/13 11:51:16 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <iostream> +#include "Fixed.hpp" + +int main(void) +{ + Fixed a; + Fixed b(a); + Fixed c; + + c = b; + std::cout << a.getRawBits() << std::endl; + std::cout << b.getRawBits() << std::endl; + std::cout << c.getRawBits() << std::endl; + return 0; +} |
