Explicit Template Argument Specification

Explicit Template Argument Specification - parameter is of...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Explicit Template Argument Specification One of the newer features in C++ is the ability to explicitly specify argument types for function templates. As a simple example of this, consider the following: template <class T> void f(int i) { T x = i; . .. } void g() { f<double>(37); } It used to be that you'd have to use all the template parameter types (like T) in the declaration of the template, but this is no longer required. In this example, T is declared via the <> specification to be of type double, and the actual function
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: parameter is of course an int. One possible application for the feature is the ability to specify what a template's return type should be: template <class T, class U, class V> V max(T t, U u) { if (t > u) return V(t); else return V(u); } void g() { int i = max<double,double,int>(12.34, 43.21); } independent of reliance on the template function arguments....
View Full Document

This note was uploaded on 02/27/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue University-West Lafayette.

Ask a homework question - tutors are online