Skip to content

Commit c0e4a38

Browse files
committed
fix cpp03
1 parent 32a1db7 commit c0e4a38

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

CPP_03/ex00/srcs/ClapTrap.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: jmartin <jmartin@student.42lausanne.ch> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2022/11/08 15:21:31 by jmartin #+# #+# */
9-
/* Updated: 2022/11/08 15:21:32 by jmartin ### ########.fr */
9+
/* Updated: 2022/11/24 10:29:57 by jmartin ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -98,7 +98,7 @@ void ClapTrap::takeDamage(unsigned int amount) {
9898
}
9999

100100
void ClapTrap::beRepaired(unsigned int amount) {
101-
if (energyCost() == 0) {
101+
if (this->getEnergyPoints() == 0) {
102102
std::cout << this->getName()
103103
<< " has no energy left."
104104
<< std::endl;
@@ -116,6 +116,7 @@ void ClapTrap::beRepaired(unsigned int amount) {
116116
<< std::endl;
117117
return ;
118118
}
119+
energyCost();
119120
this->setHitPoints(this->getHitPoints() + amount);
120121
std::cout << this->getName()
121122
<< " is repaired by "

CPP_03/ex03/srcs/DiamondTrap.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: jmartin <jmartin@student.42lausanne.ch> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2022/11/08 15:21:56 by jmartin #+# #+# */
9-
/* Updated: 2022/11/08 15:21:56 by jmartin ### ########.fr */
9+
/* Updated: 2022/11/24 10:41:31 by jmartin ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -16,9 +16,10 @@
1616
* CONSTRUCTORS / DESTRUCTORS
1717
*/
1818

19-
DiamondTrap::DiamondTrap(std::string name) : ClapTrap(name + "_clap_name"), ScavTrap(name), FragTrap(name)
19+
DiamondTrap::DiamondTrap(std::string name) : ScavTrap(name), FragTrap(name)
2020
{
2121
this->_name = name;
22+
this->ClapTrap::_name = name + "_clap_name";
2223
this->setHitPoints(FragTrap::hitPointsInit);
2324
this->setEnergyPoints(ScavTrap::energyPointsInit);
2425
this->setAttackDamage(FragTrap::attackDamageInit);
@@ -29,7 +30,7 @@ DiamondTrap::DiamondTrap(std::string name) : ClapTrap(name + "_clap_name"), Scav
2930
return ;
3031
}
3132

32-
DiamondTrap::DiamondTrap(DiamondTrap const &instance) : ClapTrap(instance), ScavTrap(instance), FragTrap(instance)
33+
DiamondTrap::DiamondTrap(DiamondTrap const &instance) : ScavTrap(instance), FragTrap(instance)
3334
{
3435
this->setName(instance.getName());
3536
std::cout << "DiamondTrap"

CPP_06/ex02/srcs/main.cpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: jmartin <jmartin@student.42lausanne.ch> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* 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 */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -50,13 +50,14 @@ void identify(Base* p)
5050
{
5151
std::cout << "Identify by pointer: \n" << GREEN;
5252

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;
6061
}
6162

6263
/*
@@ -72,7 +73,7 @@ void identify(Base& p)
7273
std::cout << GREEN << "A" << NC << std::endl;
7374
}
7475
catch (std::exception &e) {
75-
std::cout << RED << "A" << NC << std::endl;
76+
std::cerr << RED << "A" << NC << std::endl;
7677
}
7778

7879
try {
@@ -81,7 +82,7 @@ void identify(Base& p)
8182
std::cout << GREEN << "B" << NC << std::endl;
8283
}
8384
catch (std::exception &e) {
84-
std::cout << RED << "B" << NC << std::endl;
85+
std::cerr << RED << "B" << NC << std::endl;
8586
}
8687

8788
try {
@@ -90,7 +91,7 @@ void identify(Base& p)
9091
std::cout << GREEN << "C" << NC << std::endl;
9192
}
9293
catch (std::exception &e) {
93-
std::cout << RED << "C" << NC << std::endl;
94+
std::cerr << RED << "C" << NC << std::endl;
9495
}
9596
}
9697

0 commit comments

Comments
 (0)