C++ Partial Specialization ( Function Pointers )

☆樱花仙子☆ 提交于 2019-12-08 04:16:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!