Привет всем, не могу разобраться:
Создаю Singleton
SharedData.h#ifndef SHAREDDATA_H
#define SHAREDDATA_H
#include <stdio.h>
// Pattern Singleton
class SharedData
{
public:
static SharedData* Instance();
void FreeInst();
private:
static SharedData* self;
static int refcount;
SharedData();
~SharedData();
};
SharedData* SharedData::self = NULL;
int SharedData::refcount = NULL;
#endif // SHAREDDATA_H
SharedData.cpp#include "SharedData.h"
SharedData::SharedData()
{
}
SharedData::~SharedData()
{
}
SharedData* SharedData::Instance()
{
if (!self) self = new SharedData();
refcount++;
return self;
}
void SharedData::FreeInst()
{
refcount--;
if (!refcount)
{
delete this;
self = NULL;
}
}
Далее вызываю
#include "TempestLoader.h"
#include "..\SharedData\SharedData.h"
void TempestLoader::openFile(QString filename)
{
SharedData* sdata = SharedData::Instance();
}
Ошибка
TempestLoader.obj : error LNK2005: "private: static class SharedData * SharedData::self" (?self@SharedData@@0PAV1@A) already defined in SharedData.obj
TempestLoader.obj : error LNK2005: "private: static int SharedData::refcount" (?refcount@SharedData@@0HA) already defined in SharedData.obj