简体   繁体   中英

Explicit specialization of a function template for a fully specialized class template

I'm trying to specialize a function within a specialization of a class template, but can't figure the right syntax:

template< typename T >
struct Foo {};

template<>
struct Foo< int >
{
  template< typename T >
  void fn();
};

template<> template<>
void Foo< int >::fn< char >() {} // error: too many template-parameter-lists

Here I'm trying to specialize fn for char , which is inside of Foo specialized for int . But the compiler doesn't like what I write. What should be the right syntax then?

You don't have to say that you're specializing twice.

You're only specializing one function template here

template<> void Foo<int>::fn<char>() {}

Live On Coliru

template< typename T >
struct Foo {};

template<>
struct Foo< int >
{
  template< typename T >
  void fn();
};

template<> void Foo<int>::fn<char>() {}

int main() {
    Foo<int> f;
    f.fn<char>();
}

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