What is foo*(*)?

Viewed 260

In a project, I came accross following line of code.

::std::unordered_map<std::string, Channel*(*)(Module*, const Parameters&)>;

Does anyone know what Channel*(*) could mean? Is is the same as Channel**? It seems confusing and overcomplicated to me.

The Channel constructor looks like this:

Channel(Module* module, const util::Parameters& parameters);
1 Answers

This:

Channel*(*)(Module*, const Parameters&)

Is pointer to a function that takes a Module* and a const Parameters& as argument and returns a Channel*.

For more details see here: https://en.cppreference.com/w/cpp/language/pointer

Function pointers are look rather intimidating, and an alias makes using them much simpler:

using fun = Channel*(Module*, const Parameters&);
fun* x = &some_function_with_right_signature;
// or
::std::unordered_map<std::string,fptr>;
Related