我有一个用 SWIG 包装的类,它是 std::function 代理:
template <class TR = void, class ... Types>
struct GenericFunc : std::function<TR (Types...)> {
GenericFunc() {}
GenericFunc(const std::function<TR (Types... t)> & Action) : std::function<TR (Types... t)>(Action) {}
virtual TR OnAction(Types ... result) {
if(*this) {
return (*this)(result...);
}
return TR();
}
virtual ~GenericFunc(){}
};
在 C# 或 Java 中,可以重载 OnAction
并获得他想要的结果,而在 C++ 中,我们只有一个额外的检查。
拥有 Func
的人会喜欢拥有 Action
- 一个返回 void 的函数。
typedef GenericFunc<void, Types...> GenericAction<class ... Types>;
所以我想知道如何使用 typedef(而不是继承)来创建一个 Action 。并且 I get many errors
如何通过 C++11 和 typedef 包装某些类型?
最佳答案
您可以使用 alias template .
template<class... Types>
using GenericAction = GenericFunc<void, Types...>;
关于c++ - 如何使用 typedef 和可变参数模板包装除一个模板参数之外的所有模板参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30497139/