Implement solution to ex00 (without Makefile)
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 17 Oct 2024 07:37:00 +0000 (09:37 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 17 Oct 2024 07:37:00 +0000 (09:37 +0200)
ex00/Fixed.cpp [new file with mode: 0644]
ex00/Fixed.h [new file with mode: 0644]

diff --git a/ex00/Fixed.cpp b/ex00/Fixed.cpp
new file mode 100644 (file)
index 0000000..63539e0
--- /dev/null
@@ -0,0 +1,40 @@
+#include "Fixed.h"
+#include <iostream>
+
+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 (file)
index 0000000..3638837
--- /dev/null
@@ -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