Putting the following presents an error, saying it cannot convert it to type LPTHREAD_START_ROUTINE. The second one does not create this error so the cast is apparently needed, weather it's correct or not, I am not sure. The thread also behaves properly when I give it a test scenario of adding objects that I can visibly see on the screen.
Code:
hUpdateThread = CreateThread(NULL, 0, &octalTree::updateOctalTreeThread, (void*)this, 0, &threadID);
hUpdateThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&octalTree::updateOctalTreeThread, (void*)this, 0, &threadID);
Also, doing the following presents the same error of not being able to convert the cast with the cast present.
Code:
// ... rest of class above...
protected:
unsigned long updateOctalTreeThread(void* arg);
HANDLE hUpdateThread;
DWORD threadID;
};
template<class ObjectType> unsigned long octalTree<ObjectType>::updateOctalTreeThread(void* arg)
{
Sleep(2000);
octalTree* octree = (octalTree*)arg;
while(true) {
octree->destroy();
for(int i = 0; i < octree->allObjects.size(); i++) {
octree->add(octree->allObjects[i], octree->allPositions[i]);
}
}
return 0;
}
// constructor calling the thread
template<class ObjectType> octalTree<ObjectType>::octalTree(void)
{
root = new octalNode;
for(int i = 0; i < 8; i++) {
root->child[i] = NULL;
}
objectsPerNode = 1;
hUpdateThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&octalTree::updateOctalTreeThread, (void*)this, 0, &threadID);
}