C++ template; partial specialization implementation -
given template class single parameter, can define implementation specific specialization:
template<int n> struct foo { foo( ); }; foo<2>::foo( ) { //works (on ms visual 2012, though it's not correct form) }
for multiple parameter template, possible define implementation partial specialization?
template <class x, int n> struct bar { bar( ); }; template <class x> bar<x,2>::bar( ) { //error }
for partial specializations, need first define specialization of class template before can go defining members:
template <class x, int n> struct bar { bar(); }; template<class x> struct bar<x,2> { bar(); }; template <class x> bar<x,2>::bar( ) { }
the correct form first 1 said works is:
template<int n> struct foo { foo( ); }; template<> foo<2>::foo( ) { //works }
Comments
Post a Comment