C++ 标准
是否以某种方式指定了 T
在以下声明中可以是什么:
template <typename T>
我的意思是,从实用的角度来看,这可以是任何特定类型,它允许模板编译(当相应的替换发生时)。
但是严格定义呢?
最佳答案
如你所愿,这里是标准:
C++03, 14.1, 模板参数:
A template defines a family of classes or functions.
template-declaration:
exportopt template < template-parameter-list > declaration
template-parameter-list:
template-parameter
template-parameter-list , template-parameter
template-parameter:
type-parameter
parameter-declaration
type-parameter:
class identifieropt
class identifieropt = type-id
typename identifieropt
typename identifieropt = type-id
template < template-parameter-list > class identifieropt
template < template-parameter-list > class identifieropt = id-expression
..
A type-parameter defines its identifier to be a type-name (if declared with class or typename) or template-name (if declared with template) in the scope of the template declaration.
..
If the use of a template-argument gives rise to an ill-formed construct in the instantiation of a template specialization, the program is ill-formed.
其他内容用于默认参数、非类型模板等。换句话说,标准没有说明任何关于 T
的内容。
关于c++ - 模板类型名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8204608/