|
-
June 17th, 2006, 06:20 PM
#1
callback functions
Hi,
I have been trying to use callback functions without any success. I tried to follow the example B on this webpage:
http://www.newty.de/fpt/callback.html#member
Here is the code:
Code:
class aodv_rit
{
public:
static void recvPacket_callback(unsigned char *packet, int size);
int recvPacket(unsigned char *packet, int size);
}
void aodv_rit::recvPacket_callback(unsigned char *packet, int size) {
// explicitly cast to a pointer to TClassA
aodv_rit* mySelf = (aodv_rit*) pt2Object;
// call member
mySelf->recvPacket(packet, size);
}
int aodv_rit::recvPacket(unsigned char * packet, int size)
{
...
..
...
}
This callback function is used here:
Code:
returnValue = emuInit(recvPacket_callback,maxPacketSize,ID,maxNumNodes);
I have also tried these without success giving the same error:
Code:
returnValue = emuInit(&recvPacket_callback,maxPacketSize,ID,maxNumNodes);
returnValue = emuInit(aodv_rit::recvPacket_callback,maxPacketSize,ID,maxNumNodes);
returnValue = emuInit(&(aodv_rit::recvPacket_callback),maxPacketSize,ID,maxNumNodes);
emuInit is declared as follows:
Code:
int filterPacket::init(int (*callbackFunction)(unsigned char *, int), int maxBytes, unsigned char id, int numNodes)
I am getting this error from ms visual studio 2006:
error C2664: 'int (int (__cdecl *)(unsigned char *,int),int,unsigned char,int)' : cannot convert parameter 1 from 'overloaded-function' to 'int (__cdecl *)(unsigned char *,int)'
I am really confused about what could be wrong. I really hope some of the more knowledgeable people can help out. Thanks
Amish
-
June 18th, 2006, 02:43 AM
#2
Re: callback functions
Because you have:
Code:
int filterPacket::init(int (*callbackFunction)(unsigned char *, int), ...
and you actual callback is:
Code:
void aodv_rit::recvPacket_callback(unsigned char *packet, int size)
The return type doesn't match.
-
June 18th, 2006, 09:27 PM
#3
Re: callback functions
Sweet thanks for the help.
Amish
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|