# functor parameters

## Recommended Posts

edwinnie    122
hey! I am trying to pass a function into a functor's argument typelist. But this function is templated. Then I got some nasty compiler errors claiming that the argument type cannot be matched. So i was wondering if i might have missed out some kind of template magic... heres what i have tested so far:
//declare functor type
typedef Functor<bool,TYPELIST_2(int,void*)> RegType;

//the way the functor executes its callback
//which wont work though
(*regFunc)(0,CreateFunc<isPolymorphic>);

//this templated function cannot seemed to fit in the functor's 2nd argument
template<bool isPolymorphic>
BaseClass<isPolymorphic>* MyNamespace::CreateFunc()
{
return new DerivedClass<isPolymorphic>();
}

//the way the functor executes its callback
//which will work
(*regFunc)(0,CreateFunc);

//this templated function cannot seemed to fit in the functor's 2nd argument
BaseClass<true>* MyNamespace::CreateFunc()
{
return new DerivedClass<true>();
}


thx!

##### Share on other sites
Shannon Barber    1681
You can't do that; you either have to pass in an explicit template function (fill in the types fot its parameters), or you need to create a functor generator that takes the template function as a template-template parameter and can produce a functor later when you have the types.

Post the code where you actually try to create a RegType functor.

For the line:
(*regFunc)(0,CreateFunc<isPolymorphic>);
isPolymorphic has to be a compile-time boolean, but it looks like you're trying passing to pass it an arguement.

Also, add a space to this declaration:
typedef Functor<bool,TYPELIST_2(int,void*)> RegType;
typedef Functor<bool,TYPELIST_2(int,void*) > RegType;

It might fail to compile otherwise as I think the pre-processed output would have a >>.

##### Share on other sites
edwinnie    122
ah i see.
i revamped the code to use another way to get ard that problem.
thx!