feat(ex00): it works
This commit is contained in:
commit
b54faafe1d
6 changed files with 105 additions and 0 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
*.o
|
||||||
|
*.d
|
||||||
|
.cache
|
||||||
|
compile_commands.json
|
||||||
1
ex00/.gitignore
vendored
Normal file
1
ex00/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
ex00
|
||||||
29
ex00/Fixed.cpp
Normal file
29
ex00/Fixed.cpp
Normal 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
19
ex00/Fixed.hpp
Normal 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
39
ex00/Makefile
Normal 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
13
ex00/main.cpp
Normal 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;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue