Help with static data members

Hi there! In my struggle to reduce the amount of global variables in my programs, I've come across a little problem.

I have a class that need list of names, which used to be a global array of std::wstring. So I though I could make it a static data member within the class, but aparently not.
My knowledge of how static stuff works is rather slim, so help me out :)

Here is the class. I've removed the irrelevant parts:

1
2
3
4
5
6
7
8
9
10
11
class Sprite
{
private:
	static std::wstring RVNames[5];
	void SetRVPointer(std::wstring fileName);
};

void Sprite::SetRVPointer(std::wstring fileName)
{	
	RVNames[1] = L"Hi there";
}


When I try to assign a value to RVNames[1], I get this linker error. Why?

error LNK2001: unresolved external symbol "public: static class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > * Sprite::RVNames" (?RVNames@Sprite@@2PAV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@A)
What you have is only a declaration. You need also to put a definition of RVNames outside the class, in a source file.
std::wstring Sprite::RVNames[5];
That worked like a charm. Thank you :)
Topic archived. No new replies allowed.