Text based game, getting error C2227.

I am working on a text based game for a class project. I'm getting some error codes that i'm not sure how to fix. it is error code C2227. I will only put the relevant parts of the code here. I have a player class, which contains a pointer to the room which the player is in. I also have the function get_room which is to return the room the player is in. In the room class i have an array of pointers to rooms, called direction[].

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
//player class
class player {
public:

	string get_name();
	void list_inventory();
	void pick_up_item(Item item, player u);
	void set_name(string Name);
	Room* get_room();
	void set_room(Room* r);
	vector<Item> inventory;

private:
	string name;

	Room * current_room = nullptr;
};

//room class
Room {
public:
      Room(int max, int i = 0) {
		int random = 0;
		if (i != max) {
			int random = rand() % 10 - 6;
		}
		for (int j = 0; j < random; ++j) {
			direction[j] = new Room(i + 1, max);
		}


		// set room description
                // set room objects

	}

	string get_room_descr();
	void list_room_obj();
	Room * direction[4] = { nullptr, nullptr, nullptr, nullptr };

private:
	vector<Item> Room_Obj;
	string room_description;


};


Room* player::get_room() {
	return current_room;
}



In order to see if a player, 'User', can go a certain direction, I use the following to check if the direction they want to go is a nullptr.


1
2
3
if(User.get_room->direction[0] == nullptr){
 cout << "You can not go that direction" << endl;
}


Using this results in the error code C2227. Can anyone tell me what this means?
Last edited on
https://msdn.microsoft.com/en-us/library/0z8wd049.aspx
The operand to the left of -> is not a pointer to a class, structure, or union.


You need to use parentheses to call the function.
 
if(User.get_room()->direction[0] == nullptr){

Topic archived. No new replies allowed.