未解决的外部,尝试使用静态变量c ++

时间:2017-03-13 21:02:12

标签: c++ class

我在world.h中有班级世界:

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

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

在函数的另一个类中,我尝试使用静态变量:

location

并且在world.cpp中我有:

public location: any;

ngOnInit() {
        let autocomplete = new google.maps.places.Autocomplete((this.search.nativeElement), {types: ['(cities)']});

        //add event listener to google autocomplete and capture address input
        google.maps.event.addListener(autocomplete, 'place_changed', function () {
            let place = autocomplete.getPlace();
        });

}

但我收到以下错误:

  • LNK2001未解析的外部符号" public:static class Ground World :: ground" (?地面@ @@世界@@ 2PAVGround A)
  • LNK1120 1未解析的外部

image of the errors:

1 个答案:

答案 0 :(得分:2)

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

你在那里缺少World::,所以你要定义一个完全不相关的变量,它恰好具有相同的名称。你应该这样:

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