-5

So I'm trying to create what is basically a linked list of rooms that stores pointers to the previous and next room in each room.

#ifndef Hospital_Room_h
#define Hospital_Room_h

class Room
{

public:

    Room( Room  const &);
    Room createRooms();

    Room next;
    Room prev;
};

#endif
Robᵩ
  • 163,533
  • 20
  • 239
  • 308
IanPanz
  • 41
  • 1
  • 1
  • 2
  • 2
    Are you having any problems doing this? – David G Nov 29 '12 at 19:32
  • Welcome to Stack Overflow! In the editing toolbar, notice the button labeled `{}`. You can code-ify your program by selecting its text and clicking that button. I have done that for you for this program. – Robᵩ Nov 29 '12 at 19:32
  • @David: Yeah, there's a problem doing this. What's the size of a Room, if it must have two Rooms inside it? By definition, you have `sizeof(Room) >= 2 * sizeof(Room)`, which is impossible. – cHao Nov 29 '12 at 19:33
  • 1
    Use an STL linked list then. – djechlin Nov 29 '12 at 19:34

1 Answers1

4

To declare a pointer requires the * character, like so:

Room* next;
Room* prev;

To subsequently use the pointer requires either the * operator or the -> operator, like so:

myFavoriteRoom = *(myRoom.next);

myFavoriteWindow = myRoom.next -> window;

If you are trying to use pointers, but do not yet understand how they work, I suggest you follow a good book on C++ programming.

Community
  • 1
  • 1
Robᵩ
  • 163,533
  • 20
  • 239
  • 308