1

I have class World in world.h:

class World
{
public:
    static Ground* ground;
};

and in another class in a function I try to use the static variable ground like that:

#include "Node.h"
#include "World.h"
void Node::Foo()
{
    Ground* ground = World::ground;
}

and also in world.cpp i have:

#include "stdafx.h"
#include "World.h"

static Ground* ground = new Ground(10, 10);

But i get the following errors:

  • LNK2001 unresolved external symbol "public: static class Ground World::ground" (?ground@World@@2PAVGround@@A)
  • LNK1120 1 unresolved externals

image of the errors:

Kys Plox
  • 774
  • 2
  • 10
  • 23

1 Answers1

2
static Ground* ground = new Ground(10, 10);

You're missing World:: there, so you're defining a completely unrelated variable that just happens to have the same name. You should have this:

Ground* World::ground = new Ground(10, 10);