Partial template specialization of a member function: "prototype does not match"

I am trying to partially specialize a template function member of an unoccupied class:

#include <iostream> template<class T> class Foo {}; struct Bar { template<class T> int fct(T); }; template<class FloatT> int Bar::fct(Foo<FloatT>) {} int main() { Bar bar; Foo<float> arg; std::cout << bar.fct(arg); } 

I get the following error:

 c.cc:14: error: prototype for 'int Bar::fct(Foo<FloatT>)' does not match any in class 'Bar' c.cc:9: error: candidate is: template<class T> int Bar::fct(T) 

How to fix compiler error?

+6
source share
1 answer

Partial specialization of functions (member or otherwise) is not allowed.

Use overload:

 struct Bar { template<class T> int fct(T data); template<class T> //this is overload, not [partial] specialization int fct(Foo<T> data); }; 
+9
source

All Articles