什么是foo*(*)?

在一个项目中,我遇到了以下代码行。

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

有人知道 Channel*(*) 是什么意思吗?和Channel**一样吗?这对我来说似乎令人困惑和过于复杂。

Channel 构造函数如下所示:

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

回答

这个:

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

指向以 aModule*和 aconst Parameters&作为参数并返回 a的函数的指针Channel*

有关更多详细信息,请参见此处:https : //en.cppreference.com/w/cpp/language/pointer

函数指针看起来很吓人,别名使它们的使用变得更加简单:

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


以上是什么是foo*(*)?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>