473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Thread class: need help!

1
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 ;)


Expand|Select|Wrap|Line Numbers
  1. #include <windows.h>
  2. #include <stdlib.h>
  3. #include <malloc.h>
  4. #include <memory.h>
  5. #include <tchar.h>
  6.  
  7. template <class T> class Thread
  8. {
  9. public:
  10.     Thread(){}
  11.     Thread(T data){ this->data = data; }
  12.     virtual ~Thread(){}
  13.     virtual void Proc(T data);
  14.  
  15.     void Run() {
  16.         Run(data);
  17.     }
  18.  
  19.     void Run(T data) {
  20.         this->data = data;
  21.         handle = ::CreateThread(0, 0,(LPTHREAD_START_ROUTINE)ThreadFunc, (LPVOID)this, 0, 0);
  22.     }
  23.  
  24.     void Join() {
  25.         ::WaitForSingleObject(handle, INFINITE);
  26.     }
  27. private:
  28.     HANDLE handle;
  29.     T data;
  30.     static DWORD WINAPI ThreadFunc(LPVOID param)
  31.     {
  32.         Thread* This = (Thread*)param;
  33.         This->Proc(This->data);
  34.         return 0;
  35.     }
  36. };
  37.  
  38.  
  39.  
  40. class MyTask : public Thread<wchar_t*>
  41. {
  42.     void Proc(wchar_t* data)
  43.     {
  44.         ::MessageBox(NULL, L"Message from thread", data, NULL);
  45.     }
  46. };
  47.  
  48.  
  49. int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE, char*, int iShowCmd)
  50. {
  51.     MyTask * t = new MyTask();
  52.     t->Run(L"Hola!");
  53.     t->Join();
  54.     return 0;
  55. }
  56.  
Expand|Select|Wrap|Line Numbers
  1. Visual C++ 2008, Express Edition:
  2.  
  3. 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)"
  4.  
Any ideas?
May 30 '09 #1
1 1677
newb16
687 512MB
Because you haven't implemented Thread::Proc. You did it with MyTask::Proc, but not for parent template class. Either decalare it pure virtual or define with empty body.
May 31 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

44
by: Charles Law | last post by:
Hi guys. I'm back on the threading gig again. It's the age-old question about waiting for something to happen without wasting time doing it. Take two threads: the main thread and a worker...
31
by: AlexeiOst | last post by:
Everywhere in documentation there are recommendations to use threads from thread pooling for relatively short tasks. As I understand, fetching a page or multiple pages (sometimes up to 50 but not...
4
by: Leonardo Hyppolito | last post by:
Hello, I am trying to write a multithread program that simulates producers and consumers. My program can have many producers and many consumers (each in a separate thread). It has a storage...
11
by: Michael | last post by:
I am new to vb.net and just playing around to get a feel for it. I am coming from a vb6/java background so please excuse me if my idea is plain stupid or contra good programming practice in dot...
4
by: Daylor | last post by:
hi. i have multi thread application in vb.net is there a way NET support, so i can mark the class , to be access only for 1 thread each time ? if there is , small sytax sample will help ...
7
by: Charles Law | last post by:
My first thought was to call WorkerThread.Suspend but the help cautions against this (for good reason) because the caller has no control over where the thread actually stops, and it might have...
4
by: sklett | last post by:
I'm fairly new to Threading and things have been going pretty smooth so far. I did some performance testing on my new app and realized it's lagging a bit on raising events. It's a realtime app and...
2
by: Peter Thornqvist | last post by:
Hi! I have a directory and file search class that I would like to call in an asynch manner. The class is implemented such that whenever a matching item is found (directory, file, file content)...
5
by: Tony Gravagno | last post by:
I have a class that instantiates two Timer objects that fire at different intervals. My class can be instantiated within a Windows Form or from a Windows Service. Actions performed by one of the...
8
by: Brad Walton | last post by:
Hello. First post, but been doing a bit of reading here. I am working on a project in Java, but decided to switch over to C# after seeing some of the additional features I can get from C#. One of...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.