Hi,
I am learning about pointer, right now with pointer function. Lets assume, a pointer to function which takes no arguments and returns a double. So it would be,
double(*myFunc)();
Now I want a pointer to function which takes no arguments and returns ten pointers to functions, which takes no arguments and returns a double.
So wouldn't it be this:
double((*(*myFunc)())[10])();
?
But a book I am reading says quite different, it says this rather:
double (*(*(*myFunc)())[10])();
Why is this? Why I should put an extra asterisk there?
double (*(*(*myFunc)())[10])();
^
Pointer to function...
1 2 3
double (*(*(*myFunc)())[10])();
^ ^
...that returns a pointer to an array of 10...
1 2 3
double (*(*(*myFunc)())[10])();
^ ^
...pointers to functions with return type double.
It easily gets very complicated using pointers to arrays and functions. I recommend you take a look at std::function (as an alternative to function pointers) and std::array and std::vector (as an alternative to arrays). It makes life much easier.