This means that it algorithm_ptr_typeis a pointer to a function that returns solution_typeand whose parameters are:
- type problem
problem_type post_evaluation_callback, which again is a function pointer that takes two parameters ( void*and int) and returns void.
And the same can be written as ( easy and readable syntax ):
typedef void (*callback_type)(void *move, int score);
typedef solution_type (*algorithm_type)(problem_type, callback_type);
Note: the parameter name is optional, so I deleted it to make typedef short and pretty!
In C ++ 11, this can be simplified as follows:
using algorithm_ptr_type = solution_type (*) (
problem_type,
void(*)(void*, int)
);
This is much better, since it is now clear what is being determined and in terms of what.
++ 11 ,
template<typename Return, typename ... Parameters>
using make_fn = Return (*)(Paramaters...);
,
using callback_type = make_fn<void, void*, int>;
using algorithm_type = make_fn<solution_type, problem_type, callback_type>;
make_fn - , - — !
:
solution_type SomeFunction(problem_type problem, callback post_evaluation)
{
post_evaluation(arg1, arg2);
}
algorithm_ptr_type function = SomeFunction;
function(arg, someOtherFunction);