“template< class T>”之间的区别是什么,和“template< typename T>” [英] What is the difference between "template <class T>" and "template <typename T>"?
问题描述
可能重复:
对模板参数使用'class'或'typename'?
b $ b
我看到两个不同的模板类声明:
template< class T& class SampleClass1
{
// ...
};
和
template< typename T> class SampleClass2
{
// ...
};
这两个代码有什么区别?
编辑:我将错误的关键字typedef更正为typename。
If by
template< typedef T& class SampleClass2
您的意思是
template< typename T> class SampleClass2
那么没有区别。使用 class
和 typename
(在引用类型的模板参数的上下文中)是可互换的。 / p>
这里允许两个关键字的原因是历史。有关详细说明,请参见本文。
Possible Duplicate:
Use 'class' or 'typename' for template parameters?
I see two different template class declarations:
template <class T> class SampleClass1
{
// ...
};
and
template <typename T> class SampleClass2
{
// ...
};
What is the difference between these two codes?
EDIT: I corrected the wrong keyword "typedef" to "typename".
If by
template <typedef T> class SampleClass2
you mean
template <typename T> class SampleClass2
then there is no difference. The use of class
and typename
(in the context of a template parameter that refers to a type) is interchangeable.
The reason that both keywords are allowed here is historical. See this article for a detailed explanation.
这篇关于“template< class T>”之间的区别是什么,和“template< typename T>”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!