I am getting this error:
"LNK2001 unresolved external symbol "private: static class Example * Example::instance" (?instance@Example@@0PAV1@A)"
when I run the following code:
Example.h
class Example
{
private:
static Example* instance;
Example(){}
public:
static Example* Instance();
};
Example.cpp
Example* Example::Instance()
{
if (!instance)
{
instance = new Example;
}
return instance;
}
Entity.h
class Entity
{
private:
Example* example;
public:
Entity();
Example* getExample();
};
Entity.cpp
Entity::Entity() : example(Example::Instance())
{
}
Example* Entity::getExample()
{
return example;
}
I think it has something to do with this line:
Entity::Entity() : example(Example::Instance())
But why does this cause a problem?