简体   繁体   中英

What does “a member template of a class” refer to in the C++ standard?

The C++ standard states:

A template defines a family 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM