943,154 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 263
  • C++ RSS
Feb 9th, 2010
0

threads of an Object?

Expand Post »
i want to make an Object Test to control many threads.

Test.cpp
C++ Syntax (Toggle Plain Text)
  1. class Test{
  2. public:
  3. Test();
  4. void exampleThread(void*);
  5. };
  6.  
  7. Test::Test(){
  8. _beginthread(exampleThread, 0, 0);
  9. }
  10.  
  11. void Test::exampleThread(void* ptr){
  12. ...
  13. }

i get the error
Quote ...
argument of type `void (Test:: )(void*)' does not match `void (*) (void*)'
what must i write so that i can make an Object control many threads?

thanks.
Last edited by TheGhost; Feb 9th, 2010 at 7:54 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
TheGhost is offline Offline
23 posts
since Oct 2007
Feb 9th, 2010
0
Re: threads of an Object?
Do you get this error on line 8?

If you get this error on line 8, replace this line:
C++ Syntax (Toggle Plain Text)
  1. void exampleThread(void*);

by this one
C++ Syntax (Toggle Plain Text)
  1. void (*exampleThread)(void*);

Regards,,,
Kimo
Last edited by kim00000; Feb 9th, 2010 at 8:04 am.
Reputation Points: 12
Solved Threads: 11
Junior Poster in Training
kim00000 is offline Offline
84 posts
since Oct 2009
Feb 9th, 2010
0
Re: threads of an Object?
Click to Expand / Collapse  Quote originally posted by kim00000 ...
Do you get this error on line 8?
yeah, the error's on line 8.

so, what should i do?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
TheGhost is offline Offline
23 posts
since Oct 2007
Feb 9th, 2010
0
Re: threads of an Object?
I think the _beginthread takes a
void(*Somevoid)(void *)
as the first argument...

and you passed a
void Somevoid(void *) to it, so that's the reason

Regards,,,
Kimo
Reputation Points: 12
Solved Threads: 11
Junior Poster in Training
kim00000 is offline Offline
84 posts
since Oct 2009
Feb 9th, 2010
0
Re: threads of an Object?
Click to Expand / Collapse  Quote originally posted by TheGhost ...
i want to make an Object Test to control many threads.

Test.cpp
C++ Syntax (Toggle Plain Text)
  1. class Test{
  2. public:
  3. Test();
  4. void exampleThread(void*);
  5. };
  6.  
  7. Test::Test(){
  8. _beginthread(exampleThread, 0, 0);
  9. }
  10.  
  11. void Test::exampleThread(void* ptr){
  12. ...
  13. }

i get the error


what must i write so that i can make an Object control many threads?

thanks.
The short answer is you can't pass a non-static member function to _beginthread . The reason is that a member function takes a this pointer as a hidden parameter. Therefore the signature doesn't match. And of course there's no instance of Test that _beginthread knows about and could call exampleTest with.

For a solution read this. It talks about CreateThread ; I am sure you could adopt it to _beginthread as well.
Reputation Points: 707
Solved Threads: 185
Practically a Posting Shark
nezachem is offline Offline
843 posts
since Dec 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: keep track of items purchased
Next Thread in C++ Forum Timeline: C++ switch statement and file operations





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC