dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: C++
Expertise: Intermediate
Jun 14, 2004

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


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 <class type>
	type min (type t1, type t2)
	{
	  return (t1<t2 ? t1 : t2);
	}
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) ; 		
	}

Saurabh Ramya
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date