Specializing a template member function of a template class?

Posted by uj2 on Stack Overflow See other posts from Stack Overflow or by uj2
Published on 2010-06-14T19:19:03Z Indexed on 2010/06/14 19:22 UTC
Read the original article Hit count: 163

I have a template class that has a template member function that needs to be specialized, as in:

template <typename T>
class X
{
public:
    template <typename U>
    void Y() {}

    template <>
    void Y<int>() {}
};

Altough VC handles this correctly, apperantly this isn't standard and GCC complains: explicit specialization in non-namespace scope 'class X<T>'

I tried:

template <typename T>
class X
{
public:
    template <typename U>
    void Y() {}
};

template <typename T>
// Also tried `template<>` here
void X<T>::Y<int>() {}

But this causes both VC and GCC to complain.

What's the right way to do this?

© Stack Overflow or respective owner

Related posts about c++

Related posts about templates