]> git.dkaiser.de - 42/cpp02.git/commitdiff
Add main and fix format
authorDominik Kaiser <dkaiser@student.42heilbronn.de>
Thu, 13 Feb 2025 13:47:48 +0000 (14:47 +0100)
committerDominik Kaiser <dkaiser@student.42heilbronn.de>
Thu, 13 Feb 2025 13:47:48 +0000 (14:47 +0100)
ex00/Fixed.cpp
ex00/Fixed.hpp
ex00/main.cpp

index 206325d6761cd5b49457a5145ea203bd34c11ff8..02b603f1f44cbe0cce7840b834f3bdbff175cfc9 100644 (file)
@@ -6,34 +6,43 @@
 /*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/02/12 17:06:18 by dkaiser           #+#    #+#             */
-/*   Updated: 2025/02/13 13:17:58 by dkaiser          ###   ########.fr       */
+/*   Updated: 2025/02/13 14:43:55 by dkaiser          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #include "Fixed.hpp"
-
 #include <iostream>
 
-Fixed::Fixed(void) : raw_value(0) {
-  std::cout << "Default constructor called" << std::endl;
+Fixed::Fixed(void) : raw_value(0)
+{
+    std::cout << "Default constructor called" << std::endl;
 }
 
-Fixed::Fixed(const Fixed &other) : raw_value(other.getRawBits()) {
-  std::cout << "Copy constructor called" << std::endl;
+Fixed::Fixed(const Fixed &other) : raw_value(other.raw_value)
+{
+    std::cout << "Copy constructor called" << std::endl;
 }
 
-Fixed::&operator=(const Fixed &other) {
-  std::cout << "Copy assignment operator called" << std::endl;
-  this->raw_value = other.getRawBits();
+Fixed &Fixed::operator=(const Fixed &other)
+{
+    std::cout << "Copy assignment operator called" << std::endl;
+    this->raw_value = other.getRawBits();
+    return *this;
 }
 
-Fixed::~Fixed(void) { std::cout << "Destructor called" << std::endl; }
+Fixed::~Fixed(void)
+{
+    std::cout << "Destructor called" << std::endl;
+}
 
-int Fixed::getRawBits(void) const {
-  std::cout << "getRawBits member function called" << std::endl;
-  return this->raw_value;
+int Fixed::getRawBits(void) const
+{
+    std::cout << "getRawBits member function called" << std::endl;
+    return this->raw_value;
 }
-void Fixed::setRawBits(int const raw) {
-  std::cout << "setRawBits member function called" << std::endl;
-  this->raw_value = raw;
+
+void Fixed::setRawBits(int const raw)
+{
+    std::cout << "setRawBits member function called" << std::endl;
+    this->raw_value = raw;
 }
index 89ccfe5e86b449ed81898b6716383d33b9b90452..4c834df697226b996d15589c157ec621bb30c34d 100644 (file)
@@ -6,26 +6,27 @@
 /*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/02/12 17:05:34 by dkaiser           #+#    #+#             */
-/*   Updated: 2025/02/13 13:06:51 by dkaiser          ###   ########.fr       */
+/*   Updated: 2025/02/13 14:38:28 by dkaiser          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #ifndef FIXED_H_
 #define FIXED_H_
 
-class Fixed {
- public:
-  Fixed(void);
-  Fixed(const Fixed &other);
-  Fixed &operator=(const Fixed &other);
-  ~Fixed(void);
+class Fixed
+{
+  public:
+    Fixed(void);
+    Fixed(const Fixed &other);
+    Fixed &operator=(const Fixed &other);
+    ~Fixed(void);
 
-  int getRawBits(void) const;
-  void setRawBits(int const raw);
+    int getRawBits(void) const;
+    void setRawBits(int const raw);
 
- private:
-  static const int fractional_bits = 8;
-  int raw_value;
 private:
+    static const int fractional_bits = 8;
+    int raw_value;
 };
 
 #endif
index d4d0a52c2f297f023805823200c3947149a1d831..9045973c6a180d439044e8169790332197b852d9 100644 (file)
@@ -6,8 +6,21 @@
 /*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/02/12 17:04:41 by dkaiser           #+#    #+#             */
-/*   Updated: 2025/02/12 17:05:22 by dkaiser          ###   ########.fr       */
+/*   Updated: 2025/02/13 14:29:21 by dkaiser          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
-int main(void) {}
+#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;
+}