Login | Register   
RSS Feed
Download our iPhone app
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
Home » Tip Bank » C++
Language: C++
Expertise: Intermediate
Jun 3, 2004



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

Use Explicit Template Argument to Solve Template Argument Deduction

The statement below will cause ambiguity because it is violating a rule for template argument deduction. That rule is: if a template parameter is used more than once in the function parameter list, then each deduced type for its template argument must match the first deduced type.

template <class type>
	void func (type t1, type t2);
	func(4, 5.6);
As you can see, the code is deducing two different types of the template argument for the template parameter 'type'. You can resolve this situation by using Explicit Template Argument:

	func<int>(4, 5.6)
Now the template argument for "type" is explicitly specified to "int". Thus the type of template parameter is fixed and does not depend on implicit template argument deduction anymore.

Saurabh Ramya
Comment and Contribute






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



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