<分区>
我正在尝试创建一个池来管理会快速死亡和重生的小游戏对象的分配等。
为此我创建了一个池:
template <class T>
class Pool {
public:
T* obtain()
{
T* obj = 0;
if (_avaibles.size() > 0)
{
std::vector<T*>::iterator it = _avaibles.begin();
obj = *it;
_avaibles.erase(it);
}
else
obj = new T();
return obj;
}
void free(T* obj)
{
_avaibles.push_back(obj);
}
void clear()
{
std::vector<T*>::iterator it = _avaibles.begin();
while (it != _avaibles.end())
{
T act = *it;
delete act;
++it;
}
}
private:
std::vector<T*> _avaibles;
};
问题是我得到了未解析的外部符号。池被放置为类的静态成员:
static Pool<Ship> _shipPool;
这里是错误:
Error 16 error LNK2001: unresolved external symbol "private:
static class Pool<class Ship> Asdf::_shipPool"
(?_shipPool@Asdf@@0V?$Pool@VShip@@@@A) C:\-\Asdf.obj