在this question ,接受的答案使用以下语法:
typedef std::map<std::string, Base*(*)()> map_type;
谁能解释一下 (*) 是什么意思,我以前从没见过?
最佳答案
这是一个function pointer返回一个 Base
指针并且不带任何参数,例如
struct Base {};
Base* myfun() {
return 0;
}
int main() {
std::map<std::string, Base*(*)()> mymap;
mymap.insert(std::make_pair("hello", myfun));
}
关于C++ 工厂模式语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26400905/