add example for "default constructor, copy constructor, destructor, if you need one you'll need all"
add smart pointer add pointer pointer
This commit is contained in:
@@ -2,13 +2,40 @@
|
||||
|
||||
#include "Monster.h"
|
||||
|
||||
Monster::Monster(int strength) : Entity("My Monster"), _strength(strength)
|
||||
Monster::Monster() : Entity("My Monster"), _pWeapon(new Weapon())
|
||||
{
|
||||
std::cout << "Create Monster" << std::endl;
|
||||
}
|
||||
|
||||
Monster::Monster(const Monster& other) : Entity(other), ICompareable(other)
|
||||
{
|
||||
std::cout << "Create Copy of a Monster" << std::endl;
|
||||
|
||||
// shallow copy
|
||||
//this->_pWeapon = other._pWeapon;
|
||||
this->_strength = other._strength;
|
||||
this->_speed = other._speed;
|
||||
|
||||
// deep copy of internal pointers
|
||||
this->_pWeapon = new Weapon(*other._pWeapon);
|
||||
}
|
||||
|
||||
Monster::Monster(int strength) : Entity("My Monster"), _strength(strength), _pWeapon(new Weapon())
|
||||
{
|
||||
std::cout << "Create Monster with strength" << std::endl;
|
||||
|
||||
this->name = "My Monster";
|
||||
}
|
||||
|
||||
Monster::~Monster()
|
||||
{
|
||||
std::cout << "Destroy Monster" << std::endl;
|
||||
|
||||
if (_pWeapon != nullptr)
|
||||
{
|
||||
delete _pWeapon;
|
||||
_pWeapon = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
//Monster Monster::Create(Monsters type)
|
||||
|
||||
Reference in New Issue
Block a user