模板<类型名>与模板< class> [英] template<typename> vs. template<class>
问题描述
将模板参数声明为
" typename"之间是否有任何区别?或类?例如
模板<类TT f(){}
模板< typename TT g(){}
谢谢,
Jason
Is there any difference between declaring a template parameter as a
"typename" or a "class"? E.g.
template <class TT f() { }
template <typename TT g() { }
Thanks,
Jason
推荐答案
ja ************ @ gmail.com 写道:
ja************@gmail.com wrote:
将模板参数声明为
" typename"之间是否有任何区别?或类?例如。
Is there any difference between declaring a template parameter as a
"typename" or a "class"? E.g.
不等。它们是等价的。
No. They are equivalent.
ja ************ @ gmail.com 写道:
将模板参数声明为
" typename"之间是否有任何区别?或类?
Is there any difference between declaring a template parameter as a
"typename" or a "class"?
是的:''class''更令人困惑,因为类型可能实际上并不是
a类。
Yes: ''class'' is more confusing because the type might not actually be
a class at all.
Juha Nieminen写道:
Juha Nieminen wrote:
ja ************ @ gmail.com 写道:
>声明之间有什么区别吗?模板参数为
typename或类?
>Is there any difference between declaring a template parameter as a
"typename" or a "class"?
是的:''class''更令人困惑,因为类型可能实际上并不是
是一个类。
Yes: ''class'' is more confusing because the type might not actually
be a class at all.
而typename更令人困惑,因为它还有其他用途。 :-)
模板< typename容器,typename容器:: value_type>
类东西;
一个typename与class相同,但不是另一个。难道不是吗?
令人困惑?
Bo Persson
And typename is more confusing because it has other uses as well. :-)
template<typename Container, typename Container::value_type>
class something;
One typename is the same as class, but not the other. Isn''t that
confusing?
Bo Persson
这篇关于模板<类型名>与模板< class>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!