Skip to content

Latest commit

 

History

History
61 lines (55 loc) · 1.8 KB

File metadata and controls

61 lines (55 loc) · 1.8 KB
title Function Template Instantiation | Microsoft Docs
ms.custom
ms.date 11/04/2016
ms.reviewer
ms.suite
ms.technology
cpp-language
ms.tgt_pltfrm
ms.topic language-reference
dev_langs
C++
helpviewer_keywords
templates, instantiation
function templates, instantiation
instantiation, function templates
ms.assetid f22a07c7-3ad1-465a-84f5-8737e274bd47
caps.latest.revision 8
author mikeblome
ms.author mblome
manager ghogen
translation.priority.ht
cs-cz
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
pl-pl
pt-br
ru-ru
tr-tr
zh-cn
zh-tw

Function Template Instantiation

When a function template is first called for each type, the compiler creates an instantiation. Each instantiation is a version of the templated function specialized for the type. This instantiation will be called every time the function is used for the type. If you have several identical instantiations, even in different modules, only one copy of the instantiation will end up in the executable file.

Conversion of function arguments is allowed in function templates for any argument and parameter pair where the parameter does not depend on a template argument.

Function templates can be explicitly instantiated by declaring the template with a particular type as an argument. For example, the following code is allowed:

// function_template_instantiation.cpp  
template<class T> void f(T) { }  
  
// Instantiate f with the explicitly specified template.  
// argument 'int'  
//  
template void f<int> (int);  
  
// Instantiate f with the deduced template argument 'char'.  
template void f(char);  
int main()  
{  
}  

See Also

Function Templates