I'm trying to partially specialize a templated member function of an untemplated 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'm getting 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 can I fix the compiler error?
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);
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With