C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Passing function addresses as parameters (Calling convention

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Mike
Guest





PostPosted: Thu Oct 28, 2004 4:09 pm    Post subject: Passing function addresses as parameters (Calling convention Reply with 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 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





PostPosted: Thu Oct 28, 2004 4:20 pm    Post subject: Re: Passing function addresses as parameters (Calling conven Reply with quote



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





PostPosted: Thu Oct 28, 2004 9:48 pm    Post subject: Re: Passing function addresses as parameters (Calling conven Reply with quote



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





PostPosted: Thu Oct 28, 2004 10:18 pm    Post subject: Re: Passing function addresses as parameters (Calling conven Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.