I'm trying to make a text-based console video game in c++.
I have an Inventory class with a header and a source file. In the same header file I have declared a struct called STRINGSIZES
with two integer members called name and description. They are used to store the length that should be used when displaying the Items, or from which length the name will be shortened. The header file "Inventory.h" looks something like this:
#pragma once
#include <iostream>
struct STRINGSIZES { //the fixed Size with which Inventory lists will be printed
int name;
int description;
};
class Inventory
{
public:
//some unrelated code
Inventory();
static void setStringSizes(int name, int description);
private:
static STRINGSIZES stringSizes;
};
In the Inventory.cpp file, I define the setStringSizes()
method like so:
void Inventory::setStringSizes(int name, int description)
{
stringSizes.name = name;
stringSizes.description = description;
}
In my main Source.cpp file, I am firstly calling this method.
Now when I try to compile this I get the errors:
1>Inventory.obj : error LNK2001: unresolved external symbol "public: static int stringSizeNames::name" (?name@stringSizeNames@@2HA)
1>Inventory.obj : error LNK2001: unresolved external symbol "public: static int stringSizeNames::description" (?description@stringSizeNames@@2HA)
What is the problem here?