I know that unresolved external symbol means that compiler can't find definition.
I got this error
Severity Code Description Project File Line Error LNK2001 unresolved external symbol "private: static class std::set,class std::allocator > VirtualWorld::vWords" (?vWords@VirtualWorld@@0V?$set@HU?$less@H@std@@V?$allocator@H@2@@std@@A) ConsoleApplication11 c:\Users\Laptop\documents\visual studio 2015\Projects\ConsoleApplication11\ConsoleApplication11\Source.obj 1
with this code below (this code is fragments, but it's still generates this error)
#include <set>
#ifndef _TYPE_ID
#define _TYPE_ID
typedef unsigned int Id;
#endif
#ifndef _CLASS_VIRTUALWORLD
#define _CLASS_VIRTUALWORLD
class VirtualWorld
{
private:
static Id freeCounter;
static std::set<Id> vWorlds;
bool holding;
Id virtualWorldId;
static Id hold();
static void release(const Id & i);
public:
VirtualWorld();
~VirtualWorld();
Id getInstance();
void forceRelease();
};
#endif
int main() {
VirtualWorld virWorld;
return 0;
}
Id VirtualWorld::freeCounter = 1;
Id VirtualWorld::hold() {
std::set<Id>::iterator iter = vWorlds.lower_bound(freeCounter);
while (iter != vWorlds.end() && *iter == freeCounter)
{
++iter;
++freeCounter;
}
return freeCounter++;
}
void VirtualWorld::release(const Id & i) {
vWorlds.erase(i);
freeCounter = 1;
}
VirtualWorld::VirtualWorld() : holding(false) { }
VirtualWorld::~VirtualWorld()
{
if (holding) {
release(virtualWorldId);
}
}
Id VirtualWorld::getInstance() {
if (!holding) {
virtualWorldId = hold();
holding = true;
}
return virtualWorldId;
}
void VirtualWorld::forceRelease() {
if (holding) {
release(virtualWorldId);
holding = false;
}
}
I researched that I'm getting this error then trying to access vWorlds in hold() and release(int) functions. Why I'm getting this error and what should I change ?