1.问题描述
template <typename FunType, typename… Args>
void printJsonType(Json& buffer_json,FunType& func,Args&& …args){
…
func(std::forward(args)…);
}
自定义方法去调用
void printDemo(std::string ss){
…
}
printJsonType(json,printDemo,"test");
在windows平台编译会报错:
无法将参数 从“void (__cdecl *)(Json &,std::string )”转换为FunType &”
with [
FunType=void (__cdecl *)(std::string)
]
2.解决方式:
将FunType& func 改为 const FunType& func
template <typename FunType, typename… Args>
void printJsonType(Json& buffer_json,const FunType& func,Args&& …args){
…
func(std::forward(args)…);
}
3.使用lambda方式不会出现1的编译错误。