samedi 21 janvier 2017

How to store a function pointer in struct in C++?

If I have a struct that needs to store a special iteration of a function--as in the case of a tree of functions--how do I store and access it in C++?

For instance:

struct MyStruct{
    bool *my_struct_function;
}

void do_something(MyStruct s){
    if ( *(s->my_struct_function)() ) {
    }
}

This seems like it should work (right?) but I am new to C and the IDE is yelling at me.

How do I implement this?

Aucun commentaire:

Enregistrer un commentaire