C++ difference of keywords 'typename' and 'class' in templates
来源:互联网 发布:知乎发帖被删 编辑:程序博客网 时间:2024/05/22 08:18
typename and class are interchangeable in the basic case of specifying a template:
template
class Foo
{
};
and
template
class Foo
{
};
are equivalent.
Having said that, there are specific cases where there is a difference between typename and class.
The first one is in the case of dependent types. typename is used to declare when you are referencing a nested type that depends on another template parameter, such as the typedef in this example:
template
class Foo
{
typedef typename param_t::baz sub_t;
};
The second one you actually show in your question, though you might not realize it:
template < template < typename, typename > class Container, typename Type >
When specifying a template template, the class keyword MUST be used as above – it is not interchangeable with typename in this case.
You also must use class when explicitly instantiating a template:
template class Foo;
I’m sure that there are other cases that I’ve missed, but the bottom line is: these two keywords are not equivalent, and these are some common cases where you need to use one or the other.
- C++ difference of keywords 'typename' and 'class' in templates
- The Difference of Class.forName()、Class.forName().newInstance() and New in Java
- Friend class or function and nested types in class templates
- What's the difference between Interface and an abstract class in visual c#?
- what is difference between equals() and contentEquals() of String class?
- difference between Interface and abstract class in Java
- difference between Abstract class and interface in java
- difference between Abstract class and interface in java
- Difference Between Class.ForName() And ClassLoader.LoadClass() Methods In Java
- Difference between Abstract Class and Interface in Java
- TypeName 与 class (C++)
- The difference of static, readonly and const in C#
- Difference of px, dp, dip and sp in android
- Difference of px, dp, dip and sp in android
- Calculate difference between two dates (number of days) in C#?
- Difference between release and dealloc in objective-c
- What is the difference between fprintf and vfprintf in C++?
- what is the difference between definition and declaration in c
- QT Creater学习摘要
- 表达式树基础
- python问题汇总
- canvas的使用
- oc与swift混编,OC调用swift,swift调用OC
- C++ difference of keywords 'typename' and 'class' in templates
- CocoaPods安装和使用教程
- Unsupported compiler 'GCC 4.2' selected for architecture 'i386'
- C++基础:: struct vs class
- iOS 精益编程
- Android 将程序从后台转到前台
- text-indent失效的原因
- JavaScript中的setInterval用法
- php的一些代码分页!