This commit is contained in:
Camille Chauvet
2023-08-03 14:01:36 +02:00
commit 0008b7624a
18 changed files with 379 additions and 0 deletions

2
ex00/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.o
fixed

25
ex00/Makefile Normal file
View File

@ -0,0 +1,25 @@
CXX = c++
CXXFLAGS = -std=c++98 -Wall -Wextra -Werror -g -O0
SRCDIR = src
OBJDIR = obj
EXECUTABLE = fixed
SRCS = $(wildcard $(SRCDIR)/*.cpp)
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
all: $(EXECUTABLE)
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
$(EXECUTABLE): $(OBJS)
$(CXX) $(CXXFLAGS) $^ -o $@
clean:
rm -rf $(OBJDIR)/*.o
fclean: clean
rm -fr $(EXECUTABLE)
re: fclean all

0
ex00/obj/.gitkeep Normal file
View File

37
ex00/src/Fixed.cpp Normal file
View File

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

16
ex00/src/Fixed.hpp Normal file
View File

@ -0,0 +1,16 @@
class Fixed
{
private:
int _value;
static const int _nb_bits = 8;
public:
Fixed();
Fixed(const Fixed& src);
~Fixed();
Fixed &operator=(Fixed& src);
int getRawBits( void ) const;
void setRawBits( int const raw );
};

13
ex00/src/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;
}