File tree Expand file tree Collapse file tree 14 files changed +475
-5
lines changed Expand file tree Collapse file tree 14 files changed +475
-5
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ using std::string;
1313class Form {
1414public:
1515Form (void );
16+ Form (const Form& to_copy);
1617Form (string name, int grade_to_sign, int grade_to_execute);
1718Form &operator =(const Form &original);
1819~Form (void );
Original file line number Diff line number Diff line change @@ -95,4 +95,4 @@ int main(void)
9595}
9696}
9797return EXIT_SUCCESS;
98- }
98+ }
Original file line number Diff line number Diff line change @@ -9,6 +9,12 @@ Form::Form(void)
99cout << " [Form] default constructor has been called" << endl;
1010}
1111
12+ Form::Form (const Form& to_copy)
13+ : name(to_copy.name), is_signed(to_copy.is_signed),
14+ grade_to_sign(to_copy.grade_to_sign), grade_to_execute(to_copy.grade_to_execute) {
15+ cout << " [Form] <" << this ->getName () << " > copy constructor called" << endl;
16+ }
17+
1218Form::Form (string name, int grade_to_sign, int grade_to_execute)
1319: name(name), grade_to_sign(grade_to_sign), grade_to_execute(grade_to_execute)
1420{
Original file line number Diff line number Diff line change 66class ShrubberyCreationForm : AForm {
77public:
88ShrubberyCreationForm (void );
9- ShrubberyCreationForm (const );
9+ ShrubberyCreationForm (const ShrubberyCreationForm& to_copy );
1010ShrubberyCreationForm &operator =(const ShrubberyCreationForm &original);
1111~ShrubberyCreationForm (void );
1212
13-
1413private:
1514const int grade_to_sign;
1615const int grade_to_execute;
Original file line number Diff line number Diff line change @@ -6,10 +6,14 @@ using std::endl;
66
77ShrubberyCreationForm::ShrubberyCreationForm (void )
88: grade_to_sign(145 ), grade_to_execute(137 ) {
9- cout << " ShrubberyCreationForm default constructor called" << endl;
9+ cout << " [ ShrubberyCreationForm] default constructor called" << endl;
1010};
1111
12+ ShrubberyCreationForm::ShrubberyCreationForm (const ShrubberyCreationForm& to_copy)
13+ : AForm(to_copy.name, to_copy.grade_to_sign, to_copy.grade_to_execute) {
14+ cout << " [ShrubberyCreationForm] <" << this ->getName () << " > copy constructor called" << endl;
15+ }
1216
1317ShrubberyCreationForm::~ShrubberyCreationForm (void ) {
14- cout << " ShrubberyCreationForm destructor called" << endl;
18+ cout << " [ ShrubberyCreationForm] destructor called" << endl;
1519};
Original file line number Diff line number Diff line change 1+ CC = c++
2+ CFLAGS = -Wall -Wextra -Werror -std=c++98 -fsanitize=address # -DLOGS
3+ INCLUDE = -I./includes
4+ VPATH = srcs
5+ RM = rm -rf
6+
7+ GENERAL =
8+
9+ NAME = whatever
10+ SRCS = main.cpp
11+
12+ OBJ_DIR = obj
13+ OBJS = $(SRCS:%.cpp=$(OBJ_DIR ) /%.o )
14+
15+ all : $(NAME )
16+
17+ $(NAME ) : $(OBJ_DIR ) $(OBJS )
18+ $(CC ) $(CFLAGS ) $(OBJS ) -o $(NAME )
19+
20+ $(OBJ_DIR ) :
21+ mkdir -p obj
22+
23+ $(OBJ_DIR ) /% .o : % .cpp
24+ $(CC ) $(CFLAGS ) -c $< -o $@ $(INCLUDE )
25+
26+ clean :
27+ $(RM ) $(OBJ_DIR )
28+
29+ fclean : clean
30+ $(RM ) $(NAME )
31+
32+ re : fclean all
33+
34+ run : all clean
35+ ./$(NAME )
36+
37+ noleaks : re clean
38+ echo " "
39+ valgrind --leak-check=full -s ./$(NAME )
40+
41+ .PHONY : all clean fclean re run
42+
43+ # .SILENT:
Original file line number Diff line number Diff line change 1+ #ifndef WHATEVER_HPP
2+ # define WHATEVER_HPP
3+
4+ template <typename T>
5+ void swap (T& parameter1, T& parameter2)
6+ {
7+ T temp;
8+
9+ temp = parameter1;
10+ parameter1 = parameter2;
11+ parameter2 = temp;
12+ }
13+
14+ template <typename T>
15+ T min (T parameter1, T parameter2)
16+ {
17+ if (parameter1 == parameter2)
18+ return parameter2;
19+ if (parameter1 > parameter2)
20+ return parameter2;
21+ return parameter1;
22+ }
23+
24+ template <typename T>
25+ T max (T parameter1, T parameter2)
26+ {
27+ if (parameter1 == parameter2)
28+ return parameter2;
29+ if (parameter1 > parameter2)
30+ return parameter1;
31+ return parameter2;
32+ }
33+
34+ #endif // WHATEVER_HPP
Original file line number Diff line number Diff line change 1+ #include < cstdlib>
2+ #include < iostream>
3+ #include < string>
4+ #include < whatever.hpp>
5+
6+ using std::cout;
7+ using std::endl;
8+ using std::string;
9+
10+ int main (int argc, char **argv)
11+ {
12+ (void )argc;
13+ (void )argv;
14+ int a = 2 ;
15+ int b = 3 ;
16+
17+ ::swap (a, b);
18+
19+ cout << " a = " << a << " , b = " << b << endl;
20+ cout << " min(a, b) = " << ::min (a, b) << endl;
21+ cout << " max(a, b) = " << ::max (a, b) << endl;
22+
23+ string c = " chaine1" ;
24+ string d = " chaine2" ;
25+
26+ ::swap (c, d);
27+
28+ cout << " c = " << c << " , d = " << d << endl;
29+ cout << " min(c, d) = " << ::min (c, d) << endl;
30+ cout << " max(c, d) = " << ::max (c, d) << endl;
31+
32+ return EXIT_SUCCESS;
33+ }
Original file line number Diff line number Diff line change 1+ CC = c++
2+ CFLAGS = -Wall -Wextra -Werror -std=c++98 -fsanitize=address # -DLOGS
3+ INCLUDE = -I./includes
4+ VPATH = srcs
5+ RM = rm -rf
6+
7+ GENERAL =
8+
9+ NAME = iter
10+ SRCS = main.cpp
11+
12+ OBJ_DIR = obj
13+ OBJS = $(SRCS:%.cpp=$(OBJ_DIR ) /%.o )
14+
15+ all : $(NAME )
16+
17+ $(NAME ) : $(OBJ_DIR ) $(OBJS )
18+ $(CC ) $(CFLAGS ) $(OBJS ) -o $(NAME )
19+
20+ $(OBJ_DIR ) :
21+ mkdir -p obj
22+
23+ $(OBJ_DIR ) /% .o : % .cpp
24+ $(CC ) $(CFLAGS ) -c $< -o $@ $(INCLUDE )
25+
26+ clean :
27+ $(RM ) $(OBJ_DIR )
28+
29+ fclean : clean
30+ $(RM ) $(NAME )
31+
32+ re : fclean all
33+
34+ run : all clean
35+ @echo " "
36+ @echo " TEST 1"
37+ ./$(NAME ) 0
38+ @echo " "
39+ @echo " TEST 2"
40+ ./$(NAME ) nan
41+ @echo " "
42+ @echo " TEST 3"
43+ ./$(NAME ) 42.0f
44+
45+ noleaks : re clean
46+ echo " "
47+ valgrind --leak-check=full -s ./$(NAME )
48+
49+ .PHONY : all clean fclean re run
50+
51+ # .SILENT:
Original file line number Diff line number Diff line change 1+ #ifndef ITER_HPP
2+ # define ITER_HPP
3+
4+ # include < stdint.h>
5+ # include < iostream>
6+
7+ using std::cout;
8+ using std::endl;
9+
10+ template <typename T>
11+ void print_element (T &array_element) {
12+ cout << array_element << endl;
13+ }
14+
15+ template <typename T>
16+ void plus_one (T &n) {
17+ n += 1 ;
18+ }
19+
20+ template <typename T>
21+ void iter (T *address, size_t length, void (*fn)(T&))
22+ {
23+ for (size_t i = 0 ; i < length; i += 1 ) {
24+ fn (address[i]);
25+ }
26+ }
27+
28+ #endif // ITER_HPP
You can’t perform that action at this time.
0 commit comments