KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a templated class with an templated member function template<class T> class A { public: template<class CT> CT function(); }; Now I want to specialize the templated member function in 2 ways. First for having the same type as the class: template<class T> template<> // Line gcc gives an error for, see below T A<T>::function<T>() { return (T)0.0; } Second for type bool: template<class T> template<> bool A<T>::function<bool>() { return false; } Here is how I am trying to test it: int main() { A<double> a; bool b = a.function<bool>(); double d = a.function<double>(); } Now gcc gives me for the line marked above: error: invalid explicit specialization before ‘>’ token error: enclosing class templates are not explicitly specialize So gcc is telling me, that I have to specialize A, if I want to specialize function, right? I do not want to do that, I want the type of the outer class to be open ... Is the final answer: it is not possible? Or is there a way?
Tags (comma-separated)
Save Edits
Cancel