views:

51

answers:

2
template <class EventType>
class IEvent;

class IEventable;

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

What is the right way for passing template class IEvent into 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

+4  A: 

boost::function needs a type, so you cannot pass it a template's name, it has to be a template instance. So either use a specific instance

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

or put the whole thing itself into a template:

template< typename EventType >
struct foo {
  typedef boost::function<void (IEventable&, IEvent<EventType >&)> behaviorRef;
};
sbi
Could you provide some sample?
Ockonal
@Ockonal: I tried to. Does that help?
sbi
@sbi Yes, second code sample (about structure) is what I need. Thank you.
Ockonal
A: 

A class template is just a template for a class, it's not a real class yet. You need to specify the template parameters to get a class out of it, for example IEvent<int>. So you need to decide for which kind of events you want that typedef to be, for example for int:

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

Otherwise, if you want a typedef for all possible template instantiations, you need to put the typedef itself into another templated class. See sbi's answer for an example of that.

sth
Actually it's called "class template" (not "template class") - and that's, as you wrote, because it is indeed a _template_, not a _class_.
sbi
@sbi: changed that
sth