Share PowerPoint. Anywhere!

Popov

Uploaded from authorPOINT Lite
Download as Download Not Available PPT
Presentation Description

No description available

Views: 84
Like it  ( Likes) Dislike it  ( Dislikes)
Added: December 29, 2007 This presentation is Public
Presentation Category :Entertainment
Tags Add Tags
Presentation StatisticsNew!
Views on authorSTREAM: 84
Presentation Transcript

Templates Basics II : Templates Basics II Pavel Popov 22.Mai 2006 Proseminar


Contents : Contents Fundamentals In Depth Names in Templates Instantiation Template Argument Deduction Specialization and Overloading


Fundamentals In Depth : Fundamentals In Depth Member Templates Linkage of Templates Primary Templates Template Parameters Template Arguments Friends


Member Templates : Member Templates Declared like ordinary classes, except for the parameterization clause Member Function Templates cannot be declared virtual template Class List{ //a namespace scope class template public: template //an in-class member function template List(List const&); //(constructor) ... template //an in-class member class template class Node { ... } //definition ...}; template int length (List const&); //a namespace scope function template ...


Linkage of Templates : Linkage of Templates Every template must have a unique name within its scope Can not be declared in a function Class templates cannot share a name with a different kind of entity: C linkage is not allowed, C++ linkage is the default: int X; template Class X; //Error extern “C“ template void invalid (); //Error extern “C++“ template void normal ();


Primary Templates : Primary Templates Declared without adding template arguments in angle brackets after the template name: Function templates must always be primary templates! template class Box; //OK Primary Template template class Box ; //Error template void translate(T*); //OK Primary Template template void translate(T*); //Error


Template Parameters : Template Parameters Type parameters Intoduced with keyword „typename“ or „class“ (entirely eqiuvalent) A type parameter acts like a typedef name (within a template declaration) Nontype Parameters Constant values that can be determined at compile or link time The type of the value for which it stands must be An int or enum type A pointer type A reference type Declared much like variables but cannot have nontype specifiers (like static, mutable etc.) Always rvalues (their address cannot be taken and cannot be assigned to)


Slide8 : Template Template Parameters (higher order genericity) Placeholder for class templates Declared much like class templates but without keywords like struct or union: In the scope of their declaration used like other class templates The parameters of template template parameters can have default template arguments template