C++ syntax for explicit specialization of a template function in a template class? -


i have code works in vc9 (microsoft visual c++ 2008 sp1) not in gcc 4.2 (on mac):

struct tag {};  template< typename t > struct c {        template< typename tag >     void f( t );                 // declaration      template<>     inline void f< tag >( t ) {} // error: explicit specialization in };                               // non-namespace scope 'structc<t>' 

i understand gcc me move explicit specialization outside class can't figure out syntax. ideas?

// following not correct syntax, is? template< typename t > template<> inline void c< t >::f< tag >( t ) {} 

you can't specialize member function without explicitly specializing containing class.
can forward calls member function of partially specialized type:

template<class t, class tag> struct helper {     static void f(t);    };  template<class t> struct helper<t, tag1> {     static void f(t) {} };  template<class t> struct c {     // ...     template<class tag>     void foo(t t) {         helper<t, tag>::f(t);     } }; 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -