add pointer in classes

add interfaces
This commit is contained in:
2025-09-23 12:42:50 +02:00
parent 89459f9cfc
commit 5894f4008e
10 changed files with 167 additions and 5 deletions
+25 -1
View File
@@ -1,6 +1,30 @@
#include "Monster.h"
#include <iostream>
Monster::Monster()
Monster::Monster() : _pWeapon(new Weapon())
{
//ToString();
std::cout << "Monster::Monster()" << std::endl;
}
Monster::Monster(const Monster& other)
{
// shallow copy
this->_name = other._name;
//this->_pWeapon = other._pWeapon;
// deep copy
this->_pWeapon = new Weapon(*other._pWeapon);
}
Monster::~Monster()
{
std::cout << "Monster::~Monster()" << std::endl;
if (_pWeapon != nullptr)
{
delete _pWeapon;
_pWeapon = nullptr;
}
}