Hello,
I'm trying to template my ThreadHandler Class as shown below.
problem is that whatever i try i keep getting errors on the line where the queue is being defined.
and if it manages to parse past that i get lnk errors.
AI.cpp
ThreadHandler<PathStruct>::addAction(new PathStruct(pEntity, pEntity->pAI, moveToPosition, shortestPath, v, tempTerrain));
ThreadHandler.h
#pragma once
struct PathStruct;
template <typename T>
class ThreadHandler
{
private:
static queue<T*> waiting_line;
static bool threadDead;
public:
static void addAction(T* action);
static void KillThread();
static void Run(void *);
protected:
};
ThreadHandler.cpp
#include "Stdafx.h"
template <typename T> queue<T*> ThreadHandler<T>::waiting_line;
template <typename T> bool ThreadHandler<T>::threadDead;
struct PathStruct
{
Entity * entity;
AI * ai;
D3DXVECTOR3 moveToPos;
stack<D3DXVECTOR3> shortPath;
TerrainVertex * terVert;
Terrain * terrain;
PathStruct::PathStruct(Entity * pEntity, AI * pAI, D3DXVECTOR3 moveToPosition, stack<D3DXVECTOR3> shortestPath,
TerrainVertex * v, Terrain * pTerrain)
{
entity = pEntity;
ai = pAI;
moveToPos = moveToPosition;
shortPath = shortestPath;
terVert = v;
terrain = pTerrain;
}
};
template <typename T> void ThreadHandler<T>::addAction(T * action)
{
waiting_line.push(action);
}
template <typename T> void ThreadHandler<T>::KillThread()
{
while(!threadDead)
Sleep(100);
while(!waiting_line.empty())
{
waiting_line.pop();
}
}
template <typename T> void ThreadHandler<T>::Run(void * pointless)
{
threadDead = false;
while(Main::applicationRunning)
{
while(!waiting_line.empty() && Main::applicationRunning)
{
AI::CalcPath(waiting_line.front());
waiting_line.pop();
}
Sleep(100);
}
threadDead = true;
}
What am i doing wrong.