I know this question has been asked before but I can't figure out what's wrong with my program.
I have a class and a header file:
State.cpp
#include "State.h"
#include "GameObject.h"
#include <iostream>
#include <iomanip>
#include <memory>
#include <iterator>
#include <vector>
#include "wordwrap.h"
using std::string;
using std::unique_ptr;
using namespace std;
using std::list;
/**
* Current state of the game.
*/
/**
* Display the description of the room the player is in. */
void State::announceLoc() const {
this->currentRoom->describe();
}
/**
* Constructor.
* @param startRoom Pointer to the room to start in.
*/
State::State(const Room *startRoom) : currentRoom(startRoom) {};
/**
* Move to a specified room and print its description.
* @param target Pointer to the room to move to.
*/
void State::goTo(const Room *target) {
this->currentRoom = target;
this->announceLoc();
}
GameObject State::addToInv(GameObject* gameobject) {
Inventory.push_back(gameobject);
}
void State::dispInv(){
for (auto test : Inventory){
wrapOut(test->getName());
wrapEndPara();
}
}
/**
* Return a pointer to the current room.
* @return Pointer to the current room.
*/
const Room* State::getCurrentRoom() const {
return this->currentRoom;
}
and State.h
#ifndef TEXTADV_STATE_H
#define TEXTADV_STATE_H
#include "Room.h"
#include "GameObject.h"
#include <list>
using std::string;
using namespace std;
using std::list;
class State {
const Room *currentRoom;
static list<GameObject*> Inventory;
public:
GameObject addToInv(GameObject* gameobject);
void dispInv();
explicit State(const Room *startRoom);
void goTo(const Room *target);
void announceLoc() const;
const Room* getCurrentRoom() const;
};
However when I try running it I get the issue:
CMakeFiles\ott.dir/objects.a(State.cpp.obj): In function
ZN5State8addToInvEP10GameObject': H:/.0 Year 3/C and C++/CW/ott/State.cpp:49: undefined reference to
State::Inventory[abi:cxx11]' CMakeFiles\ott.dir/objects.a(State.cpp.obj): In functionZN5State7dispInvEv': H:/.0 Year 3/C and C++/CW/ott/State.cpp:54: undefined reference to
State::Inventory[abi:cxx11]' collect2.exe: error: ld returned 1 exit status mingw32-make.exe[3]: * [ott.exe] Error 1 mingw32-make.exe[2]: [CMakeFiles/ott.dir/all] Error 2 CMakeFiles\ott.dir\build.make:225: recipe for target 'ott.exe' failed CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/ott.dir/all' failed CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/ott.dir/rule' failed mingw32-make.exe[1]: [CMakeFiles/ott.dir/rule] Error 2 Makefile:117: recipe for target 'ott' failed mingw32-make.exe: * [ott] Error 2
What am I doing wrong and how do I fix this??