6
6
/* By: jmartin <jmartin@student.42lausanne.ch> +#+ +:+ +#+ */
7
7
/* +#+#+#+#+#+ +#+ */
8
8
/* Created: 2022/11/08 15:22:42 by jmartin #+# #+# */
9
- /* Updated: 2022/11/08 15:22:42 by jmartin ### ########.fr */
9
+ /* Updated: 2022/11/24 09:46:23 by jmartin ### ########.fr */
10
10
/* */
11
11
/* ************************************************************************** */
12
12
@@ -50,13 +50,14 @@ void identify(Base* p)
50
50
{
51
51
std::cout << " Identify by pointer: \n " << GREEN;
52
52
53
- if (dynamic_cast <A*>(p))
54
- std::cout << " A" << std::endl;
55
- else if (dynamic_cast <B*>(p))
56
- std::cout << " B" << std::endl;
57
- else if (dynamic_cast <C*>(p))
58
- std::cout << " C" << std::endl;
59
- std::cout << NC << std::endl;
53
+ if (dynamic_cast <A*>(p) != NULL )
54
+ std::cout << " A" << NC << std::endl;
55
+ else if (dynamic_cast <B*>(p) != NULL )
56
+ std::cout << " B" << NC << std::endl;
57
+ else if (dynamic_cast <C*>(p) != NULL )
58
+ std::cout << " C" << NC << std::endl;
59
+ else
60
+ std::cerr << RED << " Error type" << NC << std::endl;
60
61
}
61
62
62
63
/*
@@ -72,7 +73,7 @@ void identify(Base& p)
72
73
std::cout << GREEN << " A" << NC << std::endl;
73
74
}
74
75
catch (std::exception &e) {
75
- std::cout << RED << " A" << NC << std::endl;
76
+ std::cerr << RED << " A" << NC << std::endl;
76
77
}
77
78
78
79
try {
@@ -81,7 +82,7 @@ void identify(Base& p)
81
82
std::cout << GREEN << " B" << NC << std::endl;
82
83
}
83
84
catch (std::exception &e) {
84
- std::cout << RED << " B" << NC << std::endl;
85
+ std::cerr << RED << " B" << NC << std::endl;
85
86
}
86
87
87
88
try {
@@ -90,7 +91,7 @@ void identify(Base& p)
90
91
std::cout << GREEN << " C" << NC << std::endl;
91
92
}
92
93
catch (std::exception &e) {
93
- std::cout << RED << " C" << NC << std::endl;
94
+ std::cerr << RED << " C" << NC << std::endl;
94
95
}
95
96
}
96
97
0 commit comments