Passing a template to a boost function

template <class EventType>
class IEvent;

class IEventable;

typedef boost::function<void (IEventable&, IEvent&)> behaviorRef;

What is the correct way to pass an IEvent class template to a boost function? With this code, I get: error: functional cast expression list treated as compound expression error: template argument 1 is invalid error: invalid type in declaration before ‘;’ token

+3
source share
2 answers

boost::functionyou need a type, so you cannot pass it the template name, it must be an instance of the template. Therefore, either use a specific instance

typedef boost::function<void (IEventable&, IEvent<SomeEventType>&)> behaviorRef;

or put it all in a template:

template< typename EventType >
struct foo {
  typedef boost::function<void (IEventable&, IEvent<EventType >&)> behaviorRef;
};
+5
source

A class template is just a template for a class, it is not a real class yet. You need to specify the template parameters in order to extract a class from it, for example IEvent<int>. Therefore, you need to decide for what types of events you want the typedef to be, for example, for int:

typedef boost::function<void (IEventable&, IEvent<int>&)> behaviorRef;

, typedef , typedef . . sbi .

0

Source: https://habr.com/ru/post/1750014/


All Articles