VC++ 2005 Express - LNK2001 with static var
My C++ is pretty rusty so this might just be a stupid oversite but,
I'm trying to build a DLL with the following class:
//************** SoundObject.h ***************
#ifndef SOUNDOBJECT_H
#define SOUNDOBJECT_H
#define DllExport __declspec(dllexport)
typedef double SoundChunk; // This type is used by most objects in the
SoundTools library
namespace SoundTools
{
class SoundObject
{
private:
static SoundChunk _sampleRate; // default sample rate
protected:
SoundObject();
public:
static DllExport SoundChunk GetSampleRate(void);
static DllExport void SetSampleRate(SoundChunk r);
};
}
#endif
//************** SoundObject.cpp ***************
#include "SoundObject.h"
namespace SoundTools
{
SoundObject::SoundObject()
{
SoundObject::_sampleRate = 44100.0;
}
SoundChunk SoundObject::GetSampleRate()
{
return _sampleRate;
}
void SoundObject::SetSampleRate(SoundChunk r)
{
if(r > 0.0)
_sampleRate = r;
}
}
//********************************************
When I try to build the DLL I get this linker error:
SoundObject.obj : error LNK2001: unresolved external symbol "private: static
double SoundTools::SoundObject::_sampleRate"
(?_sampleRate@SoundObject@SoundTools@@0NA)
I tried some different things including declaring _sampleRate as extern and
using explicit declarations in the *.cpp file. Not sure what I'm doing
wrong.