静态成员变量可以使用list这样的STL不?
比如下面的代码,我在go.h声明了一个静态成员变量
//go.h
include <list>
#include <algorithm>
#include <vector>
using namespace std;
struct BaseStation
{
list<int> mobile;
};
class go
{
public:
static void initialize();
static BaseStation _baseStation[400];
};
但是在go.cpp中对它初始化,编译时却出了错
[cpp]//go.cpp
#include "go.h"
void go::initialize()
{
int numMobile; //the number of mobile
numMobile = 1000;
for (int i = 0; i < 1000; i++)
{
int j = i % 400; //it can use random() in here for j
BaseStation go::_baseStation[j].mobile.push_back(i);
}
}
[/cpp]
是不是静态成员变量不能使用list这样的STL
[解决办法]
可以这样用,但是必须要先初始化一次。cpp文件开始增加BaseStation go::_baseStation[400];即可
[解决办法]
//the cpp file give its def
BaseStation go::_baseStation[400];