Search code examples
c++function-pointers

Call the function using pointer-to-pointer to function


Pointers declaration:

void (**Func1Ptr)() = {NULL};//pointer-to-pointer to function
void (*Func2Ptr)() = {NULL};//pointer to function

Two functions:

void FuncA()
{
}

void FuncB()
{
}

Now Func2Ptr points to FuncA address:

Func2Ptr = FuncA;

And now Func1Ptr points to pointer to FuncA address:

Func1Ptr = &Func2Ptr;

And there is a question - how to call function using Func1Ptr?


Solution

  • how to call function using Func1Ptr?

    There are two ways/syntax for calling using Func1Ptr is as shown below:

    //dereference Func1Ptr and then dereference the result and then use the call operator ()
    (**Func1Ptr)();  
    (*Func1Ptr)(); //another way of calling
     
    

    Working demo