fix(norm): add copy contructor
This commit is contained in:
parent
7fb5f99a7a
commit
57de4fa948
20 changed files with 93 additions and 0 deletions
|
|
@ -7,6 +7,14 @@ ClapTrap::ClapTrap()
|
||||||
std::cout << "ClapTrap::ClapTrap()" << std::endl;
|
std::cout << "ClapTrap::ClapTrap()" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClapTrap::ClapTrap(const ClapTrap &other) {
|
||||||
|
name = other.name;
|
||||||
|
hit_points = other.hit_points;
|
||||||
|
energy_points = other.energy_points;
|
||||||
|
attack_damage = other.attack_damage;
|
||||||
|
std::cout << "ClapTrap::ClapTrap(const ClapTrap &other)" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
ClapTrap::ClapTrap(std::string name)
|
ClapTrap::ClapTrap(std::string name)
|
||||||
: name(name), hit_points(10), energy_points(10), attack_damage(0) {
|
: name(name), hit_points(10), energy_points(10), attack_damage(0) {
|
||||||
std::cout << "ClapTrap::ClapTrap(" << name << ")" << std::endl;
|
std::cout << "ClapTrap::ClapTrap(" << name << ")" << std::endl;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ClapTrap();
|
ClapTrap();
|
||||||
|
ClapTrap(const ClapTrap &other);
|
||||||
ClapTrap(std::string name);
|
ClapTrap(std::string name);
|
||||||
~ClapTrap();
|
~ClapTrap();
|
||||||
ClapTrap &operator=(const ClapTrap &other);
|
ClapTrap &operator=(const ClapTrap &other);
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,14 @@ ClapTrap::ClapTrap()
|
||||||
std::cout << "ClapTrap::ClapTrap()" << std::endl;
|
std::cout << "ClapTrap::ClapTrap()" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClapTrap::ClapTrap(const ClapTrap &other) {
|
||||||
|
name = other.name;
|
||||||
|
hit_points = other.hit_points;
|
||||||
|
energy_points = other.energy_points;
|
||||||
|
attack_damage = other.attack_damage;
|
||||||
|
std::cout << "ClapTrap::ClapTrap(const ClapTrap &other)" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
ClapTrap::ClapTrap(std::string name)
|
ClapTrap::ClapTrap(std::string name)
|
||||||
: name(name), hit_points(10), energy_points(10), attack_damage(0) {
|
: name(name), hit_points(10), energy_points(10), attack_damage(0) {
|
||||||
std::cout << "ClapTrap::ClapTrap(" << name << ")" << std::endl;
|
std::cout << "ClapTrap::ClapTrap(" << name << ")" << std::endl;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ClapTrap();
|
ClapTrap();
|
||||||
|
ClapTrap(const ClapTrap &other);
|
||||||
ClapTrap(std::string name);
|
ClapTrap(std::string name);
|
||||||
~ClapTrap();
|
~ClapTrap();
|
||||||
ClapTrap &operator=(const ClapTrap &other);
|
ClapTrap &operator=(const ClapTrap &other);
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,14 @@ ScavTrap::ScavTrap() {
|
||||||
attack_damage = 20;
|
attack_damage = 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScavTrap::ScavTrap(const ScavTrap &other) {
|
||||||
|
name = other.name;
|
||||||
|
hit_points = other.hit_points;
|
||||||
|
energy_points = other.energy_points;
|
||||||
|
attack_damage = other.attack_damage;
|
||||||
|
std::cout << "ScavTrap::ScavTrap(const ScavTrap &other)" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
ScavTrap::ScavTrap(std::string name) {
|
ScavTrap::ScavTrap(std::string name) {
|
||||||
std::cout << "ScavTrap::ScavTrap(" << name << ")" << std::endl;
|
std::cout << "ScavTrap::ScavTrap(" << name << ")" << std::endl;
|
||||||
hit_points = 100;
|
hit_points = 100;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
class ScavTrap : public ClapTrap {
|
class ScavTrap : public ClapTrap {
|
||||||
public:
|
public:
|
||||||
ScavTrap();
|
ScavTrap();
|
||||||
|
ScavTrap(const ScavTrap &other);
|
||||||
ScavTrap(std::string name);
|
ScavTrap(std::string name);
|
||||||
~ScavTrap();
|
~ScavTrap();
|
||||||
ScavTrap &operator=(const ScavTrap &other);
|
ScavTrap &operator=(const ScavTrap &other);
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,14 @@ ClapTrap::ClapTrap()
|
||||||
std::cout << "ClapTrap::ClapTrap()" << std::endl;
|
std::cout << "ClapTrap::ClapTrap()" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClapTrap::ClapTrap(const ClapTrap &other) {
|
||||||
|
name = other.name;
|
||||||
|
hit_points = other.hit_points;
|
||||||
|
energy_points = other.energy_points;
|
||||||
|
attack_damage = other.attack_damage;
|
||||||
|
std::cout << "ClapTrap::ClapTrap(const ClapTrap &other)" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
ClapTrap::ClapTrap(std::string name)
|
ClapTrap::ClapTrap(std::string name)
|
||||||
: name(name), hit_points(10), energy_points(10), attack_damage(0) {
|
: name(name), hit_points(10), energy_points(10), attack_damage(0) {
|
||||||
std::cout << "ClapTrap::ClapTrap(" << name << ")" << std::endl;
|
std::cout << "ClapTrap::ClapTrap(" << name << ")" << std::endl;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ClapTrap();
|
ClapTrap();
|
||||||
|
ClapTrap(const ClapTrap &other);
|
||||||
ClapTrap(std::string name);
|
ClapTrap(std::string name);
|
||||||
~ClapTrap();
|
~ClapTrap();
|
||||||
ClapTrap &operator=(const ClapTrap &other);
|
ClapTrap &operator=(const ClapTrap &other);
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,14 @@ FragTrap::FragTrap() {
|
||||||
attack_damage = 30;
|
attack_damage = 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FragTrap::FragTrap(const FragTrap &other) {
|
||||||
|
name = other.name;
|
||||||
|
hit_points = other.hit_points;
|
||||||
|
energy_points = other.energy_points;
|
||||||
|
attack_damage = other.attack_damage;
|
||||||
|
std::cout << "FragTrap::FragTrap(const FragTrap &other)" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
FragTrap::FragTrap(std::string name) {
|
FragTrap::FragTrap(std::string name) {
|
||||||
std::cout << "FragTrap::FragTrap(" << name << ")" << std::endl;
|
std::cout << "FragTrap::FragTrap(" << name << ")" << std::endl;
|
||||||
hit_points = 100;
|
hit_points = 100;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
class FragTrap : public ClapTrap {
|
class FragTrap : public ClapTrap {
|
||||||
public:
|
public:
|
||||||
FragTrap();
|
FragTrap();
|
||||||
|
FragTrap(const FragTrap &other);
|
||||||
FragTrap(std::string name);
|
FragTrap(std::string name);
|
||||||
~FragTrap();
|
~FragTrap();
|
||||||
FragTrap &operator=(const FragTrap &other);
|
FragTrap &operator=(const FragTrap &other);
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,14 @@ ScavTrap::ScavTrap() {
|
||||||
attack_damage = 20;
|
attack_damage = 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScavTrap::ScavTrap(const ScavTrap &other) {
|
||||||
|
name = other.name;
|
||||||
|
hit_points = other.hit_points;
|
||||||
|
energy_points = other.energy_points;
|
||||||
|
attack_damage = other.attack_damage;
|
||||||
|
std::cout << "ScavTrap::ScavTrap(const ScavTrap &other)" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
ScavTrap::ScavTrap(std::string name) {
|
ScavTrap::ScavTrap(std::string name) {
|
||||||
std::cout << "ScavTrap::ScavTrap(" << name << ")" << std::endl;
|
std::cout << "ScavTrap::ScavTrap(" << name << ")" << std::endl;
|
||||||
hit_points = 100;
|
hit_points = 100;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
class ScavTrap : public ClapTrap {
|
class ScavTrap : public ClapTrap {
|
||||||
public:
|
public:
|
||||||
ScavTrap();
|
ScavTrap();
|
||||||
|
ScavTrap(const ScavTrap &other);
|
||||||
ScavTrap(std::string name);
|
ScavTrap(std::string name);
|
||||||
~ScavTrap();
|
~ScavTrap();
|
||||||
ScavTrap &operator=(const ScavTrap &other);
|
ScavTrap &operator=(const ScavTrap &other);
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,14 @@ ClapTrap::ClapTrap()
|
||||||
std::cout << "ClapTrap::ClapTrap()" << std::endl;
|
std::cout << "ClapTrap::ClapTrap()" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClapTrap::ClapTrap(const ClapTrap &other) {
|
||||||
|
name = other.name;
|
||||||
|
hit_points = other.hit_points;
|
||||||
|
energy_points = other.energy_points;
|
||||||
|
attack_damage = other.attack_damage;
|
||||||
|
std::cout << "ClapTrap::ClapTrap(const ClapTrap &other)" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
ClapTrap::ClapTrap(std::string name)
|
ClapTrap::ClapTrap(std::string name)
|
||||||
: name(name), hit_points(10), energy_points(10), attack_damage(0) {
|
: name(name), hit_points(10), energy_points(10), attack_damage(0) {
|
||||||
std::cout << "ClapTrap::ClapTrap(" << name << ")" << std::endl;
|
std::cout << "ClapTrap::ClapTrap(" << name << ")" << std::endl;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ClapTrap();
|
ClapTrap();
|
||||||
|
ClapTrap(const ClapTrap &other);
|
||||||
ClapTrap(std::string name);
|
ClapTrap(std::string name);
|
||||||
~ClapTrap();
|
~ClapTrap();
|
||||||
ClapTrap &operator=(const ClapTrap &other);
|
ClapTrap &operator=(const ClapTrap &other);
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,15 @@ DiamondTrap::DiamondTrap() : FragTrap(), ScavTrap() {
|
||||||
ClapTrap::name = name + "_clap_name";
|
ClapTrap::name = name + "_clap_name";
|
||||||
std::cout << "DiamondTrap::DiamondTrap()" << std::endl;
|
std::cout << "DiamondTrap::DiamondTrap()" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DiamondTrap::DiamondTrap(const DiamondTrap &other) {
|
||||||
|
name = other.name;
|
||||||
|
hit_points = other.hit_points;
|
||||||
|
energy_points = other.energy_points;
|
||||||
|
attack_damage = other.attack_damage;
|
||||||
|
std::cout << "DiamondTrap::DiamondTrap(const DiamondTrap &other)" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
DiamondTrap::DiamondTrap(std::string name) : name(name) {
|
DiamondTrap::DiamondTrap(std::string name) : name(name) {
|
||||||
const FragTrap fragtrap = FragTrap(name);
|
const FragTrap fragtrap = FragTrap(name);
|
||||||
|
|
||||||
|
|
@ -21,11 +30,13 @@ DiamondTrap::DiamondTrap(std::string name) : name(name) {
|
||||||
ClapTrap::name = name + "_clap_name";
|
ClapTrap::name = name + "_clap_name";
|
||||||
std::cout << "DiamondTrap::DiamondTrap(" << name << ")" << std::endl;
|
std::cout << "DiamondTrap::DiamondTrap(" << name << ")" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiamondTrap &DiamondTrap::operator=(DiamondTrap &other) {
|
DiamondTrap &DiamondTrap::operator=(DiamondTrap &other) {
|
||||||
this->name = other.name;
|
this->name = other.name;
|
||||||
ClapTrap::operator=(other);
|
ClapTrap::operator=(other);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiamondTrap::~DiamondTrap() {}
|
DiamondTrap::~DiamondTrap() {}
|
||||||
|
|
||||||
void DiamondTrap::whoAmI() {
|
void DiamondTrap::whoAmI() {
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DiamondTrap();
|
DiamondTrap();
|
||||||
|
DiamondTrap(const DiamondTrap &other);
|
||||||
DiamondTrap(std::string name);
|
DiamondTrap(std::string name);
|
||||||
DiamondTrap &operator=(DiamondTrap &other);
|
DiamondTrap &operator=(DiamondTrap &other);
|
||||||
~DiamondTrap();
|
~DiamondTrap();
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,14 @@ FragTrap::FragTrap() {
|
||||||
attack_damage = 30;
|
attack_damage = 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FragTrap::FragTrap(const FragTrap &other) {
|
||||||
|
name = other.name;
|
||||||
|
hit_points = other.hit_points;
|
||||||
|
energy_points = other.energy_points;
|
||||||
|
attack_damage = other.attack_damage;
|
||||||
|
std::cout << "FragTrap::FragTrap(const FragTrap &other)" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
FragTrap::FragTrap(std::string name) {
|
FragTrap::FragTrap(std::string name) {
|
||||||
std::cout << "FragTrap::FragTrap(" << name << ")" << std::endl;
|
std::cout << "FragTrap::FragTrap(" << name << ")" << std::endl;
|
||||||
hit_points = 100;
|
hit_points = 100;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
class FragTrap : public virtual ClapTrap {
|
class FragTrap : public virtual ClapTrap {
|
||||||
public:
|
public:
|
||||||
FragTrap();
|
FragTrap();
|
||||||
|
FragTrap(const FragTrap &other);
|
||||||
FragTrap(std::string name);
|
FragTrap(std::string name);
|
||||||
~FragTrap();
|
~FragTrap();
|
||||||
FragTrap &operator=(const FragTrap &other);
|
FragTrap &operator=(const FragTrap &other);
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,14 @@ ScavTrap::ScavTrap() {
|
||||||
attack_damage = 20;
|
attack_damage = 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScavTrap::ScavTrap(const ScavTrap &other) {
|
||||||
|
name = other.name;
|
||||||
|
hit_points = other.hit_points;
|
||||||
|
energy_points = other.energy_points;
|
||||||
|
attack_damage = other.attack_damage;
|
||||||
|
std::cout << "ScavTrap::ScavTrap(const ScavTrap &other)" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
ScavTrap::ScavTrap(std::string name) {
|
ScavTrap::ScavTrap(std::string name) {
|
||||||
std::cout << "ScavTrap::ScavTrap(" << name << ")" << std::endl;
|
std::cout << "ScavTrap::ScavTrap(" << name << ")" << std::endl;
|
||||||
hit_points = 100;
|
hit_points = 100;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
class ScavTrap : public virtual ClapTrap {
|
class ScavTrap : public virtual ClapTrap {
|
||||||
public:
|
public:
|
||||||
ScavTrap();
|
ScavTrap();
|
||||||
|
ScavTrap(const ScavTrap &other);
|
||||||
ScavTrap(std::string name);
|
ScavTrap(std::string name);
|
||||||
~ScavTrap();
|
~ScavTrap();
|
||||||
ScavTrap &operator=(const ScavTrap &other);
|
ScavTrap &operator=(const ScavTrap &other);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue