template <class EventType>
class IEvent;
class IEventable;
typedef boost::function<void (IEventable&, IEvent&)> behaviorRef;
将模板类 IEvent 传递给 boost 函数的正确方法是什么?使用此代码我得到:
错误:功能转换表达式列表被视为复合表达式
错误:模板参数 1 无效
错误:‘;’标记前的声明类型无效
最佳答案
boost::function
需要一个类型,所以你不能给它传递一个模板的名字,它必须是一个模板< em>实例。所以要么使用特定的实例
typedef boost::function<void (IEventable&, IEvent<SomeEventType>&)> behaviorRef;
或者把整个事情本身放到一个模板中:
template< typename EventType >
struct foo {
typedef boost::function<void (IEventable&, IEvent<EventType >&)> behaviorRef;
};
关于c++ - 将模板传递给 boost 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3040893/