我有世界級的world.h:無法解析的外部,試圖用靜態變量C++
class World
{
public:
static 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解析的外部符號:(?地面@世界@@ 2PAVGround @@ A) 「公共靜態類地世界::地」
- LNK1120 1個無法解析外部
請包括錯誤的文本,而不是圖像 –
'靜態地面*地面=新的地面(10,10);' - >'接地*世界::地面=新的地面(10 ,10);' – George
這個問題可能是重複的,但它的含義比原來的問題要明顯得多。 OP爲+1。 – Dan