CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Jul 2012
    Posts
    2

    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!

  2. #2
    Join Date
    Jul 2012
    Posts
    2

    Re: Function pointers in structure

    Yea. There's nothing wrong with it. Sorry!

  3. #3
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,016

    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
  •  





Click Here to Expand Forum to Full Width

Featured