"类的成员模板"在C++标准中引用了什么?

Tim*_*tin 2 c++ templates

C++标准规定:

模板定义了一系列类或函数.

template-declaration:
   exportopt template < template-parameter-list > declaration
Run Code Online (Sandbox Code Playgroud)

模板声明中的声明应

  • 声明或定义函数或类,或
  • 定义成员函数,成员类或类模板的静态数据成员或嵌套在类模板中的类,或者
  • 定义类或类模板的成员模板.

这些要点中的第三点让我感到困惑.在这种情况下,"类的成员模板"的示例是什么?成员函数或嵌套类定义将包含在前两个类别之一中.当然,没有一个模板化的数据成员?这是指typedef吗?

Dav*_*eas 7

类的成员模板是一个成员函数,它本身就是一个模板,如下所示:

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
Run Code Online (Sandbox Code Playgroud)