C - Accessing Structure Function Caller

closed account (zb0S216C)
I'm a bit confused with this one. How do I access a function caller from a structure? Take the following code example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>

struct _Base
{
    int( *Caller )( void );  // Not allowed to define the body.
};

int Sample_method( void )
{
    printf( "Returning 0...\n" );
    return 0;
}

int main( )
{
    _Base Base;
    return 0;
}

How do I call the function caller from within the Base instance? It won't let me specify an identifier.
Last edited on
That's because Caller is not a function, it is a function pointer.

Thus, in your constructor (or wherever) you'll need to set it to something like so:

Base.Caller = &Sample_method;
closed account (zb0S216C)
Thank you, Firedraco. This had me confused all day! Thanks again.
For more reading, see the venerable Function Pointer Tutorials
http://www.newty.de/fpt/index.html
Topic archived. No new replies allowed.