Example Code Help

Feb 15, 2013 at 5:36am
Take this code here:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Overriding Boss Program.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

class Enemy
{
public:
	Enemy(int damage = 10): m_Damage(damage)
	{}

	void Taunt() const
	{ cout << "The enemy says he will fight you.\n"; }

	void Attack() const
	{ cout << "Attack!  Inflicts " << m_Damage << " damage points."; }
private:
	int m_Damage;
};

class Boss : public Enemy
{
public:
	Boss(int damage = 30): Enemy(damage) // call base constructor with argument
	{}

	void Taunt() const
	{ cout << "The boss says he will end your pitiful existence.\n"; }

	void Attack() const
	{
		Enemy::Attack();
		cout << " And laughs heartily at you.\n";
	}
};

int _tmain(int argc, _TCHAR* argv[])
{
	cout << "Creating an enemy.\n";
	Enemy enemy1;
	enemy1.Taunt();
	enemy1.Attack();

	cout << "\n\nCreating a boss.\n";
	Boss boss1;
	boss1.Taunt();
	boss1.Attack();
	system("Pause");
	return 0;
}


How do I implement these following functions:
1
2
3
4
5
6
Boss& operator=(const Boss& b)
{
	Enemy::operator=(b);

Boss (const Boss& b): Enemy(b)
{


Into the big code above?
Feb 15, 2013 at 10:10am
You don't need to implement assignment in this case. The defaults (copy constructor and assignment operator) will do the right thing.
Topic archived. No new replies allowed.