| View previous topic :: View next topic |
| Author |
Message |
Mike Guest
|
Posted: Thu Oct 28, 2004 4:09 pm Post subject: Passing function addresses as parameters (Calling convention |
|
|
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:worktelemetryrf04.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.
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Thu Oct 28, 2004 4:20 pm Post subject: Re: Passing function addresses as parameters (Calling conven |
|
|
Mike wrote:
| Quote: | 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
|
|
| Back to top |
|
 |
Mike Guest
|
Posted: Thu Oct 28, 2004 9:48 pm Post subject: Re: Passing function addresses as parameters (Calling conven |
|
|
Victor Bazarov wrote:
| Quote: | Mike wrote:
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 ?
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Thu Oct 28, 2004 10:18 pm Post subject: Re: Passing function addresses as parameters (Calling conven |
|
|
Mike wrote:
| Quote: | Victor Bazarov wrote:
Mike wrote:
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
|
|
| Back to top |
|
 |
|