feat(ex00): it works

This commit is contained in:
Khaïs COLIN 2025-05-13 13:38:40 +02:00
commit b54faafe1d
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
6 changed files with 105 additions and 0 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
*.o
*.d
.cache
compile_commands.json

1
ex00/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
ex00

29
ex00/Fixed.cpp Normal file
View file

@ -0,0 +1,29 @@
#include "Fixed.hpp"
#include <iostream>
const int Fixed::fracbits(8);
Fixed::Fixed() {
std::cout << "Default constructor called" << std::endl;
value = 0;
}
Fixed::Fixed(Fixed &other) {
std::cout << "Copy constructor called" << std::endl;
this->value = other.value;
}
Fixed &Fixed::operator=(Fixed &other) {
std::cout << "Copy assignment operator called" << std::endl;
this->setRawBits(other.getRawBits());
return *this;
}
Fixed::~Fixed() { std::cout << "Destructor called" << std::endl; }
int Fixed::getRawBits(void) const {
std::cout << "getRawBits member function called" << std::endl;
return value;
}
void Fixed::setRawBits(int const raw) { value = raw; }

19
ex00/Fixed.hpp Normal file
View file

@ -0,0 +1,19 @@
#ifndef FIXED_HPP
#define FIXED_HPP
class Fixed {
public:
Fixed();
Fixed(Fixed &other);
Fixed &operator=(Fixed &other);
~Fixed();
int getRawBits(void) const;
void setRawBits(int const raw);
private:
int value;
static const int fracbits;
};
#endif

39
ex00/Makefile Normal file
View file

@ -0,0 +1,39 @@
NAME = ex00
ifeq ($(CPPFLAGS),)
CPPFLAGS = -Wall -Wextra -Werror -std=c++98 -g
endif
ifeq ($(CXX),)
CXX = c++
endif
# g++ is the default on 42 computers
ifeq ($(CXX),g++)
CXX = c++
endif
srcs = \
Fixed.cpp \
main_objs = main.o $(srcs:.cpp=.o)
all_objs = $(main_objs)
deps = $(all_objs:.o=.d)
all: $(NAME)
-include $(deps)
$(NAME): $(main_objs)
$(CXX) $(CPPFLAGS) -o $@ $^
%.o: %.cpp
$(CXX) -c $(CPPFLAGS) -o $*.o $*.cpp
$(CXX) -MM $(CPPFLAGS) -MT $*.o $*.cpp > $*.d
clean:
find . -name '*.o' -print -delete
find . -name '*.d' -print -delete
fclean: clean
rm -f $(NAME)
re:
+make fclean
+make all

13
ex00/main.cpp Normal file
View file

@ -0,0 +1,13 @@
#include "Fixed.hpp"
#include <iostream>
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;
}