模板参数的缩写(Vector3 而不是 Vector<3>)

Abbreviation for template arguments (Vector3 instead of Vector<3>)

本文关键字:lt Vector gt 参数 缩写 Vector3      更新时间:2023-10-16

考虑一个template

template<int size>
class Vector{
public:
  double data[size];
}

是否有可能定义缩写,可以写类似的东西

Vector3 a;

而不是

Vector<3> a;

对于size的一般值?

如果你特别经常需要专业化,只需使用 typedef:

using Vector3 = Vector<3>;

最直接的例子是typedef Vector<3> Vector3;