gpt4 book ai didi

c++ - 什么是基数*(*)()

转载 作者:太空狗 更新时间:2023-10-29 23:36:53 24 4
gpt4 key购买 nike

有人可以为我解释一下 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com