[temp.class.general] # 13 Templates [[temp]](./#temp) ## 13.7 Template declarations [[temp.decls]](temp.decls#temp.class.general) ### 13.7.2 Class templates [[temp.class]](temp.class#general) #### 13.7.2.1 General [temp.class.general] [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/templates.tex#L2650) A[*class template*](#def:template,class "13.7.2.1 General [temp.class.general]") defines the layout and operations for an unbounded set of related types[.](#1.sentence-1) [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/templates.tex#L2656) [*Example [1](#example-1)*: It is possible for a single class templateList to provide an unbounded set of class definitions: one class List for every type T, each describing a linked list of elements of type T[.](#2.sentence-1) Similarly, a class template Array describing a contiguous, dynamic array can be defined like this:template class Array { T* v; int sz;public:explicit Array(int); T& operator[](int); T& elem(int i) { return v[i]; }}; The prefix template specifies that a template is being declared and that a[*type-name*](dcl.type.simple#nt:type-name "9.2.9.3 Simple type specifiers [dcl.type.simple]") T can be used in the declaration[.](#2.sentence-3) In other words,Array is a parameterized type withT as its parameter[.](#2.sentence-4) — *end example*] [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/templates.tex#L2686) [*Note [1](#note-1)*: When a member of a class template is defined outside of the class template definition, the member definition is defined as a template definition with the[*template-head*](temp.pre#nt:template-head "13.1 Preamble [temp.pre]") equivalent to that of the class template[.](#3.sentence-1) The names of the template parameters used in the definition of the member can differ from the template parameter names used in the class template definition[.](#3.sentence-2) The class template name in the member definition is followed by the template argument list of the [*template-head*](temp.pre#nt:template-head "13.1 Preamble [temp.pre]") ([[temp.arg]](temp.arg "13.4 Template arguments"))[.](#3.sentence-3) [*Example [2](#example-2)*: template struct A {void f1(); void f2();}; template void A::f1() { } // OKtemplate void A::f2() { } // error template struct B {void f3(); void f4();}; template void B::f3() { } // OKtemplate void B::f4() { } // error template concept C = true;template concept D = true; template struct S {void f(); void g(); void h(); template struct Inner;}; template void S::f() { } // OK, [*template-head*](temp.pre#nt:template-head "13.1 Preamble [temp.pre]")*s* matchtemplate void S::g() { } // error: no matching declaration for Stemplate requires C // ill-formed, no diagnostic required: [*template-head*](temp.pre#nt:template-head "13.1 Preamble [temp.pre]")*s* arevoid S::h() { } // functionally equivalent but not equivalenttemplate templatestruct S::Inner { }; // OK — *end example*] — *end note*] [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/templates.tex#L2742) In a partial specialization, explicit specialization or explicit instantiation of a class template, the [*class-key*](class.pre#nt:class-key "11.1 Preamble [class.pre]") shall agree in kind with the original class template declaration ([[dcl.type.elab]](dcl.type.elab "9.2.9.5 Elaborated type specifiers"))[.](#4.sentence-1)