0

I am getting the error "Room" does not name a type "Room* method name" but I have included the needed header files

I am also getting error Room has not been declared Door(bool param1, Room* param2)

lines 50 and 44 in the below image of the build

Image of Build Log showing the error

I have tried changing the order of the header file include calls but that has not fixed the problem. Sorry if this is a duplicate, I could not find an answer from any similar posts. Door.h


#ifndef DOOR_H_INCLUDED
#define DOOR_H_INCLUDED

#include "IInteractable.h"
#include "Room.h"

using namespace std;

/**
* this class will be used to handel two cases, moving the player to another
* room and to stop them from moving forward before they complete some task.
* if isLocked is true the player will need to use one of their keys to open it
*/
class Door : public IInteractable {
public:

  /**
  * sets isLocked and nextRoom
  */
  Door(bool _isLocked, Room* _nextRoom);

  ~Door();

  /**
  * move the player to the nextRoom if the door in not locked, otherwise print
  * a message to the console.
  */
  void interact();

  /**
  * sets isLocked to false
  * @return always true
  */
  bool unlock();

  /**
  * @return the nextRoom
  */
  Room* getNextRoom();

  /**
  * @return isLocked
  */
  bool getIsLocked();

private:
  bool isLocked;
  Room* nextRoom;

  /**
  * move the player to the nextRoom
  */
  void movePlayer();
};

#endif //DOOR_H_INCLUDED

Door.cpp

#include "Door.h"

Door::Door(bool _isLocked, Room* _nextRoom) {
}

Door::~Door() {
}

void Door::interact() {
}

bool Door::unlock() {
}

Room* Door::getNextRoom() {
}

bool Door::getIsLocked() {
}

void Door::movePlayer() {

}
  • 4
    Does `Room.h` include `Door.h` ? – Richard Critten Nov 15 '21 at 23:01
  • From your code it does not look like `Door.h` should include `Room.h` a forward declaration of Room would be enough. Meaning prefer to use: `class Room;` instead of `#include "Room.h"` in a header. – drescherjm Nov 15 '21 at 23:05
  • 2
    If `Door.h` includes `Room.h` you need to break the circular header loop. This question tells you how to do that: [https://stackoverflow.com/questions/625799/resolve-build-errors-due-to-circular-dependency-amongst-classes](https://stackoverflow.com/questions/625799/resolve-build-errors-due-to-circular-dependency-amongst-classes) – drescherjm Nov 15 '21 at 23:07

0 Answers0