Tham khảo tài liệu 'ansi/iso c++ professional programmer's handbook phần 7', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | ANSI ISO C Professional Programmer s Handbook - Chapter 9 - Templates const T operator unsigned int index const size_t size const Member functions of a class template can be defined outside the class body. In this case they have to be explicitly declared as member functions of their class template. For example definitions of Vector s member functions follow the class declaration template class T Vector T Vector T size_t s constructor definition sz s buff new T s template class T Vector T Vector T const Vector T v copy ctor sz 0 buff 0 this v use overloaded assignment operator template class T Vector T Vector T operator assignment operator const Vector T v if this v return this this- Vector T Vector T call destructor buff new T allocate sufficient storage for size_t i 0 i i buff i v i memberwise copy sz return this template class T Vector T Vector T destructor delete buff template class T inline T Vector T operator unsigned int i return buff i template class T inline const T Vector T operator const version unsigned int i const return buff i template class T inline size_t Vector T size const return sz The prefix template class T indicates that T is a template parameter which is a placeholder for a yet unspecified type. The keyword class is of particular interest because the corresponding argument for the parameter file D Cool Stuff old ftp 1 1 ch09 3 von 22 14 46 22 ANSI ISO C Professional Programmer s Handbook - Chapter 9 - Templates T is not necessarily a user-defined type it can also be a fundamental type such as char or int. If you prefer a more neutral term you can use the typename keyword instead typename also has other uses though as you will see next template typename T class Vector typename instead of class no semantic difference between the two forms . template typename T Vector T Vector T size_t s sz s buff new T s Within the scope of Vector qualification with the parameter T is redundant so the member .