c++ - Instantiation/Template function specialization -
i'm reading book on c++ , reason can't seem understand template specialization (implicit template instantiation, explicit template instantiation, , explicit specialization) of functions.
to clear, don't understand need explicit template instantiation or explicit specialization when 1 declare/define non-template function, override both generic template function , specialization.
where, when, , why use explicit template instantiation and/or explicit specialization of functions?
one area useful when want overload functions different return type. not supported normal functions there no way compiler resolve ambiguity of 1 variant call. template functions can achieve this
template<typename t> t func() { ... } template<> std::string func() { ... } template<> bool func() { ... }
Comments
Post a Comment