[temp.mem.func] # 13 Templates [[temp]](./#temp) ## 13.7 Template declarations [[temp.decls]](temp.decls#temp.mem.func) ### 13.7.2 Class templates [[temp.class]](temp.class#temp.mem.func) #### 13.7.2.2 Member functions of class templates [temp.mem.func] [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/templates.tex#L2751) A member function of a class template may be defined outside of the class template definition in which it is declared[.](#1.sentence-1) [*Example [1](#example-1)*: template class Array { T* v; int sz;public:explicit Array(int); T& operator[](int); T& elem(int i) { return v[i]; }}; declares three member functions of a class template[.](#1.sentence-2) The subscript function can be defined like this:template T& Array::operator[](int i) {if (i<0 || sz<=i) error("Array: range error"); return v[i];} A constrained member function can be defined out of line:template concept C = requires {typename T::type;}; template struct S {void f() requires C; void g() requires C;}; templatevoid S::f() requires C { } // OKtemplatevoid S::g() { } // error: no matching function in S — *end example*] [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/templates.tex#L2796) The[*template-argument*](temp.names#nt:template-argument "13.3 Names of template specializations [temp.names]")*s* for a member function of a class template are determined by the[*template-argument*](temp.names#nt:template-argument "13.3 Names of template specializations [temp.names]")*s* of the type of the object for which the member function is called[.](#2.sentence-1) [*Example [2](#example-2)*: The[*template-argument*](temp.names#nt:template-argument "13.3 Names of template specializations [temp.names]") forArray​::​operator[] will be determined by theArray to which the subscripting operation is applied[.](#2.sentence-2) Array v1(20); Array v2(30); v1[3] = 7; // Array​::​operator[] v2[3] = dcomplex(7,8); // Array​::​operator[] — *end example*]