C++中为什么定义别名时using比typedef更好-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

C++中为什么定义别名时using比typedef更好

这篇文章主要介绍“C++中为什么定义别名时using比typedef更好”,在日常操作中,相信很多人在C++中为什么定义别名时using比typedef更好问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”C++中为什么定义别名时using比typedef更好”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

创新互联建站是专业的上城网站建设公司,上城接单;提供网站设计、做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行上城网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

T.43: 定义别名时,using比typedef更好

Reason(原因)

Improved readability: With using, the new name comes first rather than being embedded somewhere in a declaration. Generality: using can be used for template aliases, whereas typedefs can't easily be templates. Uniformity: using is syntactically similar to auto.

提高可读性:使用using,新名称最先出现,而不是嵌入在声明的某个地方。通用性:using可以用于模板别名,然而typedef无法简单地用于模板。统一性:using在句法上和auto相似。

Example(示例)

typedef int (*PFI)(int);   // OK, but convoluted

using PFI2 = int (*)(int);   // OK, preferred

template
typedef int (*PFT)(T);      // error

template
using PFT2 = int (*)(T);   // OK
Enforcement(实施建议)
  • Flag uses of typedef. This will give a lot of "hits" :-(

  • 标记使用typedef的地方。会有发现大量使用typedef的代码:-(

到此,关于“C++中为什么定义别名时using比typedef更好”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!


文章题目:C++中为什么定义别名时using比typedef更好
链接URL:http://kswsj.cn/article/pogsoj.html

其他资讯