views:

529

answers:

1

Can any one please tell, whether below is legal c++ or not ?

template < typename s , s & (*fn) ( s * ) > 
class c {};

// partial specialization

template < typename s , s & (*fn) ( s * ) > 
class c < s*, s* & (*fn)(s**)  {};

g++ ( 4.2.4) error: a function call cannot appear in a constant-expression error: template argument 2 is invalid

Although it does work for explicit specialization

int & func ( int * ) { return 0; }
template <> class c < int , func> class c {};
+7  A: 

I think you mean

template < typename s , s & (*fn) ( s * ) > 
class c {};

// partial specialization
template < typename s , s & (*fn) ( s * ) > 
class c < s*, fn >  {};
James Hopkin
Actually, I want to specialize second argument on the basis of first type ? Does it make sense ?
@Shaikh: That's exactly what James's answer does. What's confusing you?
j_random_hacker
thumbs up! :)