【发布时间】:2016-04-08 20:12:25
【问题描述】:
以下是thiscppreference 页面关于变量模板的摘录
在类范围内使用时,变量模板声明一个静态数据 成员模板。
using namespace std::literals; struct matrix_constants { template<class T> using pauli = hermitian_matrix<T, 2>; // alias template template<class T> // static data member template static constexpr pauli<T> sigma1 = { { 0, 1 }, { 1, 0 } }; template<class T> static constexpr pauli<T> sigma2 = { { 0, -1i }, { 1i, 0 } }; template<class T> static constexpr pauli<T> sigma3 = { { 1, 0 }, { 0, -1 } }; };
C++ 标准 (N4140) 在第 14.1 (1.4) 段中说明如下:
类范围的变量模板是静态数据成员模板。
因此,在我看来,上面链接中的声明不需要存储类说明符static。我说的对吗?
P.S.:我刚刚开始对模板进行调查。
【问题讨论】:
-
您确定要使用可变模板开始您的模板调查吗?可能是更直接的东西?
-
@SergeyA 我知道标准不是学习 C++ 的最佳场所,但现在,这就是我正在做的事情,即我正在遵循标准。
-
@Barry 但是C++0z 仍然没有更正上面显示的示例。
-
@JohnKalane 是的,不幸的是该示例仍然不正确(请参阅 Richard Smith 在链接问题中的评论)
标签: c++ templates static c++14