I have seemingly simple and straightforward segment of code that is a simplified version of a problem I have been having in a game I am writing. I am trying to set a static field in one class to another value from my main method. However this code will not and I don't understand why.
I get the error
1>Source.obj : error LNK2001: unresolved external symbol "public: static class A * B::a" (?a@B@@2PAVA@@A)
class A
{
public:
A()
{
}
};
class B
{
public:
static A* a;
};
int main()
{
B::a = new A;
}
What is the rule saying that I have to define my static class member outside the class to get it linked?