c++ - specializing template member function to work in a different way for a special template class -
i have 2 classes class , class b both of them template classes member function in want act in special way when type of b , in normal way other types don't know how ?
template <class b> class b { private: t m; public: ...... member functions } template <class t> class { private: t var; public: void dosomething(); }; template <class t> void a<t>::dosomething(){...........//implementation} template <class t> void a<b<t>>::dosomething(){................//different implementation}
you can specialize a
way:
template <class t> class a<b<t>> { // ... };
this instance of partial template specialization.
if refuse specialize entire class, can defer work a<t>::dosomething()
function dosomethingfora<t>(a &)
partially specialized, , possibly friend of a<t>
.
Comments
Post a Comment