Dear experts, you help is necessary!
When trying to compile this code an error encounted.
I think that thread in class is good idea for c++, so if you know what`s wrong, please post your opinion!
(and sorry for my broken english ;)
-
#include <windows.h>
-
#include <stdlib.h>
-
#include <malloc.h>
-
#include <memory.h>
-
#include <tchar.h>
-
-
template <class T> class Thread
-
{
-
public:
-
Thread(){}
-
Thread(T data){ this->data = data; }
-
virtual ~Thread(){}
-
virtual void Proc(T data);
-
-
void Run() {
-
Run(data);
-
}
-
-
void Run(T data) {
-
this->data = data;
-
handle = ::CreateThread(0, 0,(LPTHREAD_START_ROUTINE)ThreadFunc, (LPVOID)this, 0, 0);
-
}
-
-
void Join() {
-
::WaitForSingleObject(handle, INFINITE);
-
}
-
private:
-
HANDLE handle;
-
T data;
-
static DWORD WINAPI ThreadFunc(LPVOID param)
-
{
-
Thread* This = (Thread*)param;
-
This->Proc(This->data);
-
return 0;
-
}
-
};
-
-
-
-
class MyTask : public Thread<wchar_t*>
-
{
-
void Proc(wchar_t* data)
-
{
-
::MessageBox(NULL, L"Message from thread", data, NULL);
-
}
-
};
-
-
-
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE, char*, int iShowCmd)
-
{
-
MyTask * t = new MyTask();
-
t->Run(L"Hola!");
-
t->Join();
-
return 0;
-
}
-
-
Visual C++ 2008, Express Edition:
-
-
1>App.obj : error LNK2001: unresolved external symbol ""public: virtual void __thiscall Thread<wchar_t *>::Proc(wchar_t *)" (?Proc@?$Thread@PA_W@@UAEXPA_W@Z)"
-
Any ideas?