C++编程思想 第2卷 第5章 深入理解模板 模板参数 typename关键字 用typename代替class

关键字typename的作用
可以在模板定义的模板参数列表中选择使用typename 代替class

//: C05:UsingTypename.cpp
// From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison.
// (c) 1995-2004 MindView, Inc. All Rights Reserved.
// See source code use permissions stated in the file 'License.txt',
// distributed with the code package available at www.MindView.net.
// Using 'typename' in the template argument list.

template<typename T> class X {};

int main() {
  X<int> x;
} ///:~

无输出

对大多数程序而言
这种描述方式是代码更一目了然

猜你喜欢

转载自blog.csdn.net/eyetired/article/details/82083060