Customize Your Template Function

Customize Your Template Function

If a function instantiated from a generic template definition does not suit your need, it’s possible to provide a specialized definition for that function template instantiation. Take a look at this:

	template 	type min (type t1, type t2)	{	  return (t1

Say you need to compare two literal strings. The function instantiated from the generic template definitions won't work for you. In this case, you can provide the specialized definition of the function template instantiation which otherwise would be generated from generic template definition. Like this:

		template<>const char*min (const char* t1, const char* t2)	{	    return (strcmp (t1, t2) < 0 ? t1 : t2) ; 			}
See also  Essential Measures for Safeguarding Your Digital Data

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist