C 模板类包装任何功能
C++ template class to wrap a whatever function
我想包含任何输入/输出类型的函数。在下面,我尝试使用C 模板。
double foo(double x){return x*x;}
template <typename funct>
class TestFunction{
public:
TestFunction(const funct& userFunc): f(userFunc){}
private:
const funct& f;
};
template <typename funct>
TestFunction<funct> createTestFunction(const funct& f){
return TestFunction<funct>(f);
}
int main(){
TestFunction<> testFunc=createTestFunction(foo);
}
编译此程序给我错误消息:
too few template arguments for class template 'TestFunction'
为什么C 编译器无法推断用于测试功能的类型&lt;>?我该如何修复?谢谢。另外,是否有不太尴尬的方法?
TestFunction<> testFunc = createTestFunction(foo);
应该是
auto testFunc = createTestFunction(foo);
相关文章:
- 是否有任何C++功能可以对地图进行排序?
- RtMidi - MidiInDummy:此类不提供任何功能
- 是否有任何模式等效于虚拟模板功能?
- 是否有任何功能可以通过按不同的按钮来更改操作
- C 中的余弦功能,没有任何数学功能
- 如何子类可运行任何成员功能
- 构造函数超载以接受任何功能
- 任何操作员,功能调用和构造函数的通用持续时间表
- 任何挂钩功能的单一接口
- 我可以使用QT的OpenGL功能而没有任何小部件
- C 库中是否有任何功能将字符串转换为算术操作
- 可用于任何大小的数组的功能
- C 模板功能是否有任何方法可以采用n个参数
- c++ 是否允许在任何功能之外调用函数?
- LDAP函数中是否有任何功能可以在不使用ldap_search的情况下获取用户信息
- C 模板类包装任何功能
- 如何使用C 在Arduino上制作LED闪光灯,但除了Millis()之外,没有使用任何功能
- 我想知道是否有任何功能或方法可以首先检查文件是否已创建
- 以下 2 个代码片段之间是否有任何功能差异
- C或C++或WinApi中是否有任何功能来创建目录,包括指定路径中所有不存在的目录