LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-25-2005, 10:07 PM   #1
crapodino
Member
 
Registered: Aug 2005
Distribution: SuSE 10
Posts: 72

Rep: Reputation: 15
Problem with a thread class in c++


Hi i am using suse 9.3 prof and kdevelope. I have a proble using posix threads in c++... I have include <pthread.h>

I have a class called Thread with 2 single methods:

void* Thread::func(void*) {

return NULL;
}

and i have another methos like this:

pthread_t Thread::makeThread( pthread_attr_t attr, void* arg ) {
pthread_t aux;
int answer;

answer=pthread_create(&aux,attr,func,arg);
return aux;
}

The problem is that it can't compile because it says:

erro: argument of type ' void*(Thread:void*)/ does not match 'void* (*) (void*)


In fact, i have this 2 methodes in a same class and i want to make a thread that takes as a parametre a own methode, like in this case "func"

I have trie to put instead of func:
(void*)func
Thread::func
(void*)Thread::func
(void*)&func
and so on


please!! i really need to solve this!

ahh if i put the method func as static it works, but the problem is that i can't use it as static

thaks
 
Old 09-26-2005, 08:02 AM   #2
Hivemind
Member
 
Registered: Sep 2004
Posts: 273

Rep: Reputation: 30
If you want to have a class member function to be the entry point it *has* to be a static member function. And if that static member function needs to access non-static members of the class, the usual solution is to pass a pointer to the class instance to the entry function. This topic has come up lots of times on several forums, I suggest you acquire some basic google skills.

Last edited by Hivemind; 09-26-2005 at 08:04 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Implementing a vector class from a list class purefan Programming 9 04-14-2005 10:48 PM
BlackBox.class & VerifierBug.class virus ??? dalek Linux - Security 4 02-29-2004 08:55 AM
Inheriting class members (Qt C++, QApplication class) jtshaw Programming 2 01-15-2004 11:52 AM
Communicating Class A and Class C Networks chadtce Linux - Networking 10 07-23-2003 01:36 PM
c++ : regarding (inheritence)base class and derived class edreddy Programming 6 07-31-2002 06:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration