简体   繁体   中英

C++ Partial Specialization ( Function Pointers )

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 {};

I think you mean

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM