Specialization of a member function of a variational class template without a template

I had a problem with this code:

#include <iostream> using namespace std; class A { public: template<typename T, typename... Args> void stuff(Args... args); }; template<typename T, typename... Args> void A::stuff(Args... args) { cout << sizeof...(args) << endl; } template<> void A::stuff<int>() { cout << "int" << endl; } int main() { A a; A b; a.stuff<char>(); b.stuff<int>(); } 

Trying to compile it , I get this error:

 template-id 'stuff<int>' for 'void A::stuff()' does not match any template declaration 

What am I doing wrong? I tried this without variability and it worked, but how do I specialize the Variadic template member function?

+4
source share
1 answer

It looks like an error. The problem is not limited to fully specialized member function templates. It can be reproduced even using free function templates as follows:

 template<typename T, typename... Args> void stuff2(Args... args); template<typename T, typename... Args> void stuff2(Args... args) { cout << sizeof...(args) << endl; } template<> void stuff2<int>() { cout << "int" << endl; } int main() {} 

While clang 3.2 compiles this just fine, gcc complains about:

spec.cpp: 31: 6: error: template-id 'stuff2' for 'void stuff2 ()' does not match any template declaration

There is a related SO question .

A message seems to confirm that this is indeed a mistake.

+5
source

All Articles