-
August 22nd, 2012, 10:11 PM
#1
Function pointers in structure
Hi,
I have a function pointer in a structure like this-
Code:
typedef struct mystruct
{
int (*fp)(int,int);
}mystruct;
I initialize this func pointer in a function like this-
Code:
void Init(mystruct *handle,int (*my_fp)(int,int))
{
handle->fp=my_fp;
}
thenI'm trying to use this function pointer in another function, like this-
Code:
int func(mystruct *handle)
{
int c=handle->fp(1,2);
return c;
}
Somehow, it is giving me a lot of syntax errors. Please tell me what I'm doing wrong here!
-
August 22nd, 2012, 11:33 PM
#2
Re: Function pointers in structure
Yea. There's nothing wrong with it. Sorry!
-
August 24th, 2012, 10:18 PM
#3
Re: Function pointers in structure
Glad it is working. However, you should try to post these questions in the C++ forums, rather than the more general algorithms and data structures forum. Those are a little more high traffic (more eyeballs!) and people more likely to know how to fix syntax problems.
However! If you have questions about algorithms and data structures at a bit of a higher level, this is the right sub-forum.
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
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
|