Passing function addresses as parameters (Calling convention problems)

M

Mike

I want to pass the address of a function to a timeout type class so that
it can be used as a callback function.

The function I want to use as a callback is defined like...

void rf04::rc_proc(void)
{
}

The call to the the function that uses this functions' address is like...

rctimer=new Timeout(rf04::rc_proc);

But the compiler complains with ...

h:\work\telemetry\rf04.cpp(81) : error C2664: 'Timeout::Timeout' :
cannot convert parameter 1 from 'void (void)' to 'void (__cdecl *)(void)'

I tried defining my callback function as

_CRTIMP void __cdecl rf04::rc_proc(void)

but then the compiler complained that I was not allowed to use dllimport
functions in this way.

Linux and g++ complains in a different way...

g++ -Wall -g -O -c rf04.cpp
rf04.cpp: In method `rf04::rf04 (char *)':
rf04.cpp:82: assuming & on `rf04::rc_proc'
rf04.cpp:82: no matching function for call to `Timeout::Timeout (void
(rf04::*) ())'
timeout.h:19: candidates are: Timeout::Timeout (void (*) (), unsigned
int = 1000)
timeout.h:29: Timeout::Timeout (const Timeout &)
make: *** [rf04.o] Error 1

I'm at bit of a loss to understand what is going on. I never really
understood #pragma and stuff like that, but I suspect it's siomething to
do with that.

If my call back function was a global function and not part of a class
then the code compiles and runs OK.

Can anyone give me some clues on this.

Thanks.
 
V

Victor Bazarov

Mike said:
I want to pass the address of a function to a timeout type class so that
it can be used as a callback function.

The function I want to use as a callback is defined like...

void rf04::rc_proc(void)
{
}

The call to the the function that uses this functions' address is like...

rctimer=new Timeout(rf04::rc_proc);

But the compiler complains [...]

This is covered in the FAQ. Please see the section on pointers to
members.

V
 
M

Mike

Victor said:
Mike said:
I want to pass the address of a function to a timeout type class so
that it can be used as a callback function.

The function I want to use as a callback is defined like...

void rf04::rc_proc(void)
{
}

The call to the the function that uses this functions' address is like...

rctimer=new Timeout(rf04::rc_proc);

But the compiler complains [...]


This is covered in the FAQ. Please see the section on pointers to
members.

V

Which FAQ ? Where ?
 
V

Victor Bazarov

Mike said:
Victor said:
Mike said:
I want to pass the address of a function to a timeout type class so
that it can be used as a callback function.

The function I want to use as a callback is defined like...

void rf04::rc_proc(void)
{
}

The call to the the function that uses this functions' address is
like...

rctimer=new Timeout(rf04::rc_proc);

But the compiler complains [...]



This is covered in the FAQ. Please see the section on pointers to
members.

V


Which FAQ ? Where ?

Haven't you read the Welcome message on your way in?

http://www.slack.net/~shiva/welcome.txt

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top