目前,我实现了两个模板函数,每区选出一个模板函数指针使用boost ::包裹变种:模板函数返回模板函数指针
功能发
typedef boost::variant<&A<int>,&A<double>> A_T; A_T fa(string type) { switch(type){ case "int": return &A<int>; case "double": return &A<double>; default: return &A<int>; } }
功能FB
typedef boost::variant<&B<int>,&B<double>> B_T; B_T fb(string type) { switch(type){ case "int": return &B<int>; case "double": return &B<double>; default: return &B<int>; } }
我的问题是“我们可以将两个函数合并为一个模板函数,它将A或B的函子指针作为模板参数吗?”。为什么我需要这个的原因是因为我可以有两个以上的函子像A和B.
这是什么语言?它看起来不像有效的C++代码。我建议你生成一个[mcve] –
如果这与你的实际实现类似,你的第一步就是尝试运行你已经通过编译器得到的东西,并找出出现的几个错误。 – aschepler