473,405 Members | 2,261 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,405 software developers and data experts.

method type void* (*) (void*)



I am getting

task.cpp:109: error: argument of type 'void (Spac_task::)()' does not
match 'void* (*)(void*)'

when trying to execute the line
int thr_id = pthread_create(&p_thread, NULL, spc_optm, NULL);

where

void Spac_task::spc_optm(){/*...*/}

if I change it to
void* Spac_task::spc_optm(void*){/*...*/}

then I get

task.cpp:109: error: argument of type 'void* (Spac_task::)(void*)'
does not match 'void* (*)(void*)'

I even tried

static void* (*) spc_optm(void*);

static void* (*) Spac_task::spc_optm(void*){/*...*/}

that did not cut it.

any guide?

thanks alot
Nov 17 '06 #1
5 5386
Gary Wessle wrote:
I am getting

task.cpp:109: error: argument of type 'void (Spac_task::)()' does not
match 'void* (*)(void*)'

when trying to execute the line
int thr_id = pthread_create(&p_thread, NULL, spc_optm, NULL);

where

void Spac_task::spc_optm(){/*...*/}
Sure. You are trying to make a member function the thread function.
You can't. A thread function has to be static or global.

The function spc_optm is a member function. It has an implied this
pointer. That is, it needs a class instance to run. That;s likely why
you were trying to do this, to put an object in charge of a thread.
But how does the call you made know about the instance of the
class you want it to be handled by?

There are a few ways to deal with this. One is read the FAQ, as
it gets asked fairly regularly. Look up "callback" and such. This
is a variant on a callback.
Socks

Nov 17 '06 #2
On 17 Nov 2006 11:18:18 -0800, "Puppet_Sock" wrote:
>Gary Wessle wrote:
>I am getting
task.cpp:109: error: argument of type 'void (Spac_task::)()' does not
match 'void* (*)(void*)'
Sure. You are trying to make a member function the thread function.
You can't. A thread function has to be static or global.
There are a few ways to deal with this. One is read the FAQ,
http://www.parashift.com/c++-faq-lit...o-members.html

Nov 17 '06 #3
Gary Wessle wrote:
>
I am getting

task.cpp:109: error: argument of type 'void (Spac_task::)()' does not
match 'void* (*)(void*)'

when trying to execute the line
int thr_id = pthread_create(&p_thread, NULL, spc_optm, NULL);

where

void Spac_task::spc_optm(){/*...*/}

if I change it to
void* Spac_task::spc_optm(void*){/*...*/}

then I get

task.cpp:109: error: argument of type 'void* (Spac_task::)(void*)'
does not match 'void* (*)(void*)'

I even tried

static void* (*) spc_optm(void*);

static void* (*) Spac_task::spc_optm(void*){/*...*/}

that did not cut it.

any guide?

thanks alot
You need a non member or static "start routine" method - I pulled this
from at_posix_thread_cpp.i from Austria C++ ...

void * start_routine( void * i_task )
{
Spac_task * l_this_task = static_cast<Spac_task *>( i_task );

l_this_task->spc_optm();
....
// You also need to get the thread_id so you can join to it.
int l_result = pthread_create(
& m_task_context->m_thread_id,
static_cast<const pthread_attr_t *>( 0 ),
& start_routine,
static_cast<void *>( pointer_to_Spac_task )
);

if ( 0 != l_result )
{
abort();
}
Then again - you just use Austria's thread (Task) class or boost's
thread classes.
Nov 17 '06 #4
rp*****@yahoo.com (Roland Pibinger) writes:
On 17 Nov 2006 11:18:18 -0800, "Puppet_Sock" wrote:
Gary Wessle wrote:
I am getting
task.cpp:109: error: argument of type 'void (Spac_task::)()' does not
match 'void* (*)(void*)'
Sure. You are trying to make a member function the thread function.
You can't. A thread function has to be static or global.
There are a few ways to deal with this. One is read the FAQ,

http://www.parashift.com/c++-faq-lit...o-members.html
thanks

following the example in the FAQ,
void spac_task::spc_optm(){/*...*/}

void Spac_task::preform(){
/*...*/
pthread_t p_thread;
int thr_id = pthread_create(&p_thread, NULL, spc_optm, NULL);
}

is being replaced by:

Spac_task* signal_handle;
void spac_memb_f_wrap(){
signal_handle->spc_optm;
}
signal(SIGINT, spac_mem_f_wrap);

but I don't see how the threading takes place in above replacement.
is it done behind the seen?

thanks
Nov 17 '06 #5
rp*****@yahoo.com (Roland Pibinger) writes:
On 17 Nov 2006 11:18:18 -0800, "Puppet_Sock" wrote:
Gary Wessle wrote:
I am getting
task.cpp:109: error: argument of type 'void (Spac_task::)()' does not
match 'void* (*)(void*)'
Sure. You are trying to make a member function the thread function.
You can't. A thread function has to be static or global.
There are a few ways to deal with this. One is read the FAQ,

http://www.parashift.com/c++-faq-lit...o-members.html
I read the FAQ relating to this problem which is at
http://www.parashift.com/c++-faq-lit....html#faq-33.2

I am having hard time applying the principle to my problem.

the principle is:

// Wrapper function uses a global to remember the object:
Waiter* object_which_will_handle_signal;
void Waiter_memberFn_wrapper()
{
object_which_will_handle_signal->waiting();
}

int main(){
signal(SIGINT, Waiter_memberFn_wrapper);
}
how do I apply this to my code below?

************************************************** **************
#include <boost/thread/thread.hpp>
#include <iostream>
using namespace std;
class Waiter {
short customers_serv;
public:
Waiter(short);
void waiting();
void preform();
};
Waiter::waiter(short cs) : customers_serv( cs ) {
preform();
}

void Waiter::waiting(){
customers_serv--; // modify the object
cout << "serving " << customers_serv << " customers" << endl;
}
void Waiter::preform(){
boost::thread thrd( waiting );
thrd.join();
}

int main()
{
Waiter jack(5);
Waiter sofi(2);
}
Nov 18 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Medi Montaseri | last post by:
Hi, Given a collection of similar but not exact entities (or products) Toyota, Ford, Buick, etc; I am contemplating using the Abstraction pattern to provide a common interface to these products....
5
by: Andy | last post by:
Hi Could someone clarify for me the method parameter passing concept? As I understand it, if you pass a variable without the "ref" syntax then it gets passed as a copy. If you pass a...
4
by: daniel.w.gelder | last post by:
I wrote a template class that takes a function prototype and lets you store and call a C-level function, like this: inline string SampleFunction(int, bool) {..} functor<string (int, bool)>...
5
by: kuvpatel | last post by:
Hi I want to refer a class called LogEvent, and use one of its methods called WriteMessage without actually having to create an instance of Logevent. I have tried using the word sealed with...
10
by: John Bowman | last post by:
Hello, I need some help getting a callback delegate passed as an argument to a dynamically linked Dll method so it in turn, can eventually call it. Below is the salient portions of code I'm...
5
by: RickDee | last post by:
Please help, anybody. I am trying to write a program so that it can launch an exe file ( which is also genereated in C# ) and then simulate the button clicking and invoke the methods inside the...
6
by: | last post by:
I'm new to VS.NET, C#, and the enumerated datatype. I'm told that VS.NET 2005 Intellisense will pop up the members of an enum as a selection list if you are using the enum as a method parameter....
2
by: Christophe | last post by:
class A {} class B {} interface MyInterface { void method(A a); void method(B b); }
5
by: Ronin | last post by:
I need a little help trying to figure out the last piece of this puzzle. I've got a form with an associated toolbox that will allow a user to drag a control off the toolbox and drop it onto the...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.