有人可以为我解释一下 Base*(*)() 吗:
typedef std::map<std::string, Base*(*)()> map_type;
如何从函数返回它?
我假设它是一个函数指针,返回一个Base*,但是这个(*)是什么。
我在以下 SO 帖子中找到了这个 Is there a way to instantiate objects from a string holding their class name?
谢谢
最佳答案
Base* (*)()
是一种类型:指向函数返回 Base*
的指针。 *
表示它是一个指针,()
用于覆盖优先级以确保指针适用于函数本身而不是返回类型。
您可以通过返回适当类型的函数名称来从函数中返回它。
例如
Base* f();
Base* (*g())()
{
return f;
}
关于c++ - 什么是基数*(*)(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11816964/