【发布时间】:2017-03-13 21:02:11
【问题描述】:
我在 world.h 中有 World 类:
class World
{
public:
static Ground* ground;
};
在函数的另一个类中,我尝试像这样使用静态变量 ground:
#include "Node.h"
#include "World.h"
void Node::Foo()
{
Ground* ground = World::ground;
}
在 world.cpp 中我也有:
#include "stdafx.h"
#include "World.h"
static Ground* ground = new Ground(10, 10);
但我收到以下错误:
- LNK2001 未解析的外部符号“public: static class Ground World::ground”(?ground@World@@2PAVGround@@A)
- LNK1120 1 未解决的外部问题
【问题讨论】:
-
请将错误信息作为文本,而不是图像
-
static Ground* ground = new Ground(10, 10);->Ground* World::ground = new Ground(10, 10); -
这个问题可能是重复的,但它的措辞比原来的问题要清楚得多。 +1 为 OP。