add smart pointers

add polymorphism
add destructor & copy constructor
add pointer-pointer
This commit is contained in:
2025-09-22 18:22:03 +02:00
parent d8f6014fab
commit 3b35b973c9
13 changed files with 208 additions and 7 deletions
+30 -1
View File
@@ -1,6 +1,35 @@
#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;
}
}
int Monster::Compare(ICompareable* pOther)
{
return 0;
}