正在加载图片...
Template Instantiation In and of itself, the template does nothing When the compiler encounters a template it stores the template but doesn't generate any machine instructions or codes When a function template is instantiated Compiler finds type parameters in list of function template For each type in the function parameter list, type of corresponding argument is determined These two function type and argument type are then bound together E.g., when it encounters a call to swap( EXample: swap(int, int)i it generates an integer instance of swap() The type will be determined by the compiler (at compilation time from the type of the arguments passed when swap() is called Cannot specify data type at run time COMP 152Template Instantiation ▪ In and of itself, the template does nothing ▪ When the compiler encounters a template • it stores the template • but doesn't generate any machine instructions or codes ▪ When a function template is instantiated • Compiler finds type parameters in list of function template • For each type in the function parameter list, type of corresponding argument is determined • These two function type and argument type are then bound together ▪ E.g., when it encounters a call to swap() • Example: swap(int, int); • it generates an integer instance of swap() ▪ The type will be determined … • by the compiler (at compilation time) • from the type of the arguments passed • when swap() is called ▪ Cannot specify data type at run time COMP152 13
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有