【发布时间】:2015-05-28 04:14:07
【问题描述】:
我有一个用 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>;
所以我想知道如何使用 typedefs(而不是继承)创建一个动作。还有I get many errors
如何通过 C++11 和 typedef 包装一些类型?
【问题讨论】:
标签: c++ c++11 typedef variadic-templates