How to display the name of a monster?

Hello guys.

I am currently creating a C++ based game as a refresher for an entry level C++ position interview and I want to display the type of monster, but I cannot get the type to display, I end up getting a C3867 error.
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
  class Monster {
protected:
	string type;
	int hp;
	int attack;

public:
	void createMonster() {
		int num = rand() & 3;
		
		switch (num) {
		case 0:
			type = "Werewolf";
			hp = 50;
			attack = 5;
			break;

		case 1:
			type = "Frankenstein";
			hp = 75;
			attack = 10;
			break;

		case 2:
			type = "Mummy";
			hp = 60;
			attack = 10;
			break;
		}
	}

	string getMonstertype() {
		cout << type << endl;
		return type;
	}
};

int main()
{
	Player player1;
	Monster monster1;
	

	player1.setName();
	player1.getName();
	player1.setHealth();
	player1.getHealth();

	monster1.createMonster();
	cout << "A " << monster1.getMonstertype << " appeared!" << endl;

	return 0;


Thank you in advance.
Function calls usually involve parens.

BTW, what is the name of the company? Do they really hire beginners? Why?
getMonstertype() is a (member) function; call it.

1
2
// cout << "A " << monster1.getMonstertype << " appeared!" << endl;
cout << "A " << monster1.getMonstertype() << " appeared!" << endl;
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

class Monster {

protected:
	std::string type;
	int hp;
	int attack;

public:
	Monster() { // constructor

		const int num = std::rand() % 3;

		switch (num) {

		case 0:
			type = "Werewolf";
			hp = 50;
			attack = 5;
			break;

		case 1:
			type = "Frankenstein";
			hp = 75;
			attack = 10;
			break;

		case 2:
			type = "Mummy";
			hp = 60;
			attack = 10;
			break;
		}
	}

	std::string get_type() const { return type ; }

	std::ostream& print( std::ostream& stm = std::cout ) const {

	     return stm << "monster{ type:" << type << ", hp:" << hp
	                << ", attack:" << attack << " }" ;
	}

	friend std::ostream& operator<< ( std::ostream& stm, const Monster& m ) {

	    return m.print(stm) ;
    }
};

int main()
{
    // seed the legacy rng once, at the start of he program
    std::srand( std::time(nullptr) ) ;

	const Monster a_monster; // create a monster (note:its constructor is invoked)

	std::cout << "the monster " << a_monster << " appeared!\n" ;

	// or, alternately
	std::cout << "the monster " ;
	a_monster.print() ;
	std::cout << " appeared!\n" ;

	// or, cute
	a_monster.print( std::cout << "the monster " ) << " appeared!\n" ;
}

http://coliru.stacked-crooked.com/a/983d6f8cf3383a4c
BTW, what is the name of the company? Do they really hire beginners? Why?

It's not unusual for employers - in any profession - to take on novices (on low wages, of course) and train them on the job. In trades, this is normally known as "apprenticeship", but I've seen white-collar professions do similar things too. The employer gets a cheap employee, who will - hopefully - turn into a more experienced, trained employee with - hopefully - some loyalty to the company that took them on and trained them.
I end up getting a C3867 error


A valuable skill for a C++ programmer is understanding what is C++, and what is your tools.

C3867 error isn't a C++ thing; it's a label your chosen compiler/IDE chooses to put on a particular violation of C++. Anyone using a different compiler/IDE will have no idea what you're talking about. Anyone using the same probably also has no idea what you're talking about because nobody memorises these labels.

When you are asking about errors from the compiler, you need to give the actual error. Not the label your particular compiler/IDE has given it.
Topic archived. No new replies allowed.