在C++模板中的类型参数一般可以使用typename和class,两者没有什么不同。但是typename比class多项功能:

“任何时候当你想要在template中指涉一个嵌套从属类型名称,就必须在其前面加上关键字typename”

因为C++默认情况下把属性都作为值来看待而不是类型。

#include <iostream>
#include <cstdlib> class Integer {
public:
typedef int value_type;
}; class Double {
public:
typedef double value_type;
}; template<class DataType>
class Storage {
public:
typename DataType::value_type data;
}; int main() {
Storage<Integer> s; s.data = 3.4/; std::cout<<s.data<<std::endl; return ;
}

Effective C++ .44 typename和class的不同的更多相关文章

  1. Effective Java 44 Write doc comments for all exposed API elements

    Principle You must precede every exported class, interface, constructor, method, and field declarati ...

  2. Effective Java Index

    Hi guys, I am happy to tell you that I am moving to the open source world. And Java is the 1st langu ...

  3. DAY1 linux 50条命令

    1. tar压缩,解压缩 tar -cvf *** (压缩) tar -xvf ***  (解压缩) [root@bogon ~]# tar cvf test.tar test/ test/ test ...

  4. C++ 仿函数/函数指针/闭包lambda

    在上一篇文章中介绍了C++11新引入的lambda表达式(C++支持闭包的实现),现在我们看一下lambda的出现对于我们编程习惯的影响,毕竟,C++11历经10年磨砺,出140新feature,对于 ...

  5. 50个最常用的Linux命令

    转载至:http://gywbd.github.io/posts/2014/8/50-linux-commands.html tar grep find ssh sed awk vim diff so ...

  6. linux 常用 掌握要点 详细终结

    linux 命令大全 每个开发者应该了解的 10 个 Linux 命令 1.查看正在执行的进程(Process) ps命令 Process Status 进程状态 语法: ps  [option]   ...

  7. Linux常用的50个命令

    50个最常用的Unix/Linux命令 2014-08-20 这篇文章翻译自http://www.thegeekstuff.com/2010/11/50-linux-commands/这些都是一些很常 ...

  8. 50个最常用的UNIX/Linux命令

    转自http://get.jobdeer.com/493.get 1. tar command examples Create a new tar archive. $ tar cvf archive ...

  9. 写代码怎能不会这些Linux命令?

    转自:https://zhuanlan.zhihu.com/p/28674639?hmsr=toutiao.io&utm_medium=toutiao.io&utm_source=to ...

随机推荐

  1. CentOS 中文支持

    其中通过 yum 方式安装的最简单快速: yum groupinstall "Chinese Support" 装完中文语言包之后,它不会自己变成中文,得修改文件/etc/sysc ...

  2. UIView中的tintColor和renderingMode

    tintColor 每一个view都有一个tintcolor,类似于魔法色,实现类似于换肤的效果. 每一个view的subview都集成view的tintcolor,当然subview可以指定自己的t ...

  3. [转] git merge 将多个commit合并为一条之--squash 选项

    [FROM] https://blog.csdn.net/themagickeyjianan/article/details/80333645 1.一般的做法(直接git merge) Git相对于C ...

  4. supervisor使用小记

    最近使用supervisor部署爬虫,百度了很多,磕磕绊绊自己也算是用起来了,以下是整理的使用情况. 第一步: 下载安装supervisor 使用的ubuntu16.04,直接 sudo apt-ge ...

  5. odoo 开发 context 上下文的用法

    context   这是一个上下文,运用很灵活  得到整个context   self.context_get() self.env['res.users'].context_get() 得到cont ...

  6. Docker入门笔记(1)

    Docker入门笔记(1) 1.安装Docker yum -y install docker-ce 2.查看Docker版本 [root@localhost ~]# docker -v Docker ...

  7. 简说LINUX 下chmod|chown|chgrp和用法和区别

    1.chgrp(改变文件所属用户组) chgrp 用户组    文件名    ###就是这个格了.如果整个目录下的都改,则加-R参数用于递归. 如:chgrp  -R    user  smb.con ...

  8. Java_方法的基本语法格式

    [修饰符] 返回值类型 方法名称([参数列表]){ 方法体 } [ ]中的内容是可有可无的 暂时将方法的修饰符编写为 public static 返回值类型有两种情况 : 第一种:无返回值类型,也就是 ...

  9. java实现多线程的4种方式

    1.继承Thread类 看jdk源码可以发现,Thread类其实是实现了Runnable接口的一个实例,继承Thread类后需要重写run方法并通过start方法启动线程. 继承Thread类耦合性太 ...

  10. TortoiseGit学习系列之Git和TortoiseGit的区别

    不多说,直接上干货! Git和TortoiseGit的区别: TortoiseGit的安装和使用依赖Git.