c++ - Specialization of templated member function in templated class -


i have templated class templated member function

template<class t> class { public:     template<class ct>     ct function(); }; 

now want specialize templated member function in 2 ways. first having same type class:

template<class t> template<>  // line gcc gives error for, see below t a<t>::function<t>() {     return (t)0.0; } 

second type bool:

template<class t> template<> bool a<t>::function<bool>() {     return false; } 

here how trying test it:

int main() {     a<double> a;     bool b = a.function<bool>();     double d = a.function<double>(); } 

now gcc gives me line marked above:

error: invalid explicit specialization before ‘>’ token error: enclosing class templates not explicitly specialize 

so gcc telling me, have specialize a, if want specialize function, right? not want that, want type of outer class open ...

is final answer: not possible? or there way?

yes, problem:

error: enclosing class templates not explicitly specialized  

you cannot specialize member without specializing class.

what can put code function in separate class , specialize that, basic_string depends on separate char_traits class. then non-specialized function can call helper in traits class.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -