我想用我的自定義模板鏈表類,並得到了鏈接錯誤來實現粒子系統:與模板類鏈接錯誤
Error 3 error LNK2019: unresolved external symbol "public: struct Node<class Particle> * __thiscall LinkedList<class Particle>::Pop(void)" ([email protected][email protected]@@@@[email protected]@@@@XZ) referenced in function "private: void __thiscall ParticleEmitter::addParticles(void)" ([email protected]@@AAEXXZ)*
這裏是Node.h:
template <class T>
struct Node
{
Node(const T&);
~Node();
T* value;
Node* previous;
Node* next;
};
這裏在addParticle代碼:
LinkedList<Particle> freeParticles; //definition in ParticleEmitter.h
void ParticleEmitter::addParticles(void)
{
int numParticles = RandomGetInt(minParticles, maxParticles);
for (int i = 0; i < numParticles && !freeParticles.IsEmpty(); i++)
{
// grab a particle from the freeParticles queue, and Initialize it.
Node<Particle> *n = freeParticles.Pop();
n->value->init(color,
position,
direction * RandomGetFloat(velMin, velMax),
RandomGetFloat(lifetimeMin, lifetimeMax));
}
}
這裏是流行音樂功能:
//Pop from back
template <class T>
Node<T>* LinkedList<T>::Pop()
{
if (IsEmpty()) return NULL;
Node<T>* node = last;
last = last->previous;
if (last != NULL)
{
last->next = NULL;
if (last->previous == NULL) head = last;
}
else head = NULL;
node->previous = NULL;
node->next = NULL;
return node;
}
我從頭開始編寫所有的代碼,所以也許我在某個地方犯了一個錯誤,我也是新的模板。
[模板運算符鏈接程序錯誤](http://stackoverflow.com/questions/3007251/template-operator-linker-error)(和更多,但這個有一個很好的和「教誨」接受的答案) –