问题
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 {};
回答1:
I think you mean
template < typename s , s & (*fn) ( s * ) >
class c {};
// partial specialization
template < typename s , s & (*fn) ( s * ) >
class c < s*, fn > {};
来源:https://stackoverflow.com/questions/882478/c-partial-specialization-function-pointers