map存放函数指针

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_40167046/article/details/91543046
#include <map>
#include <vector>

typedef double (*MyCalFun_ptr)(const std::vector<int> &);
std::map<std::string,MyCalFun_ptr> func_list;  //存放自定义的函数名,及其功能实现函数
double mymax(const std::vector<int> &token_list)
{
	std::size_type token_size = token_list.size();
	maxnum = token_list[0];
	for(std::size_type i = 0 ; i < token_size ; ++i)
	{
		if(token_list[i] > max)
		{
			max = token_list[i]
		}
	}
	return max;
}
std::map<std::string,MyCalFun_ptr> func_list {{"MAX",mymax}}

猜你喜欢

转载自blog.csdn.net/qq_40167046/article/details/91543046