The C++ standard states:
A template defines a famil开发者_如何学编程y of classes or functions.
template-declaration: exportopt template < template-parameter-list > declaration
The declaration in a template-declaration shall
- declare or define a function or a class, or
- define a member function, a member class or a static data member of a class template or of a class nested within a class template, or
- define a member template of a class or class template.
The third of these bullet points is what is confusing me. What is an example of "a member template of a class" in this context? A member function or nested class definition would be included in one of the first two categories. Surely there's no such thing as a templatised data member? Is this referring to typedefs?
A member template of a class is a member function that is itself a template, like these:
class test {
template <typename T> void foo(); // member template of class
};
template <typename T>
void test::foo<T>() {} // definition
template <typename T>
class test2 {
template <typename U> void foo(); // member template of class template
};
template <typename T>
template <typename U>
void test2<T>::foo<U>() {} // definition
精彩评论