decltype和typeof之间的区别? [英] Difference between decltype and typeof?

查看:2066
本文介绍了decltype和typeof之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关 decltype 两种问题




  • decltype typeof 运算符之间有什么区别吗?

  • 在C ++ 11中, typeof 是否过时?


c ++ 中没有 typeof 运算符。虽然大多数编译器提供了这样的功能已经有一段时间了,但它一直是编译器特定的语言扩展。因此,比较两者的行为通常没有意义,因为 typeof (如果它甚至存在)的行为是非常依赖于平台的。



由于我们现在有一个获取变量/表达式类型的标准方法,因此没有理由依赖非可移植扩展,所以我会说



另一件需要考虑的事情是,如果行为是 typeof 与给定编译器的 decltype 不兼容,有可能 typeof 扩展将不会得到很多开发在未来包含新的语言功能(意味着它可能根本不适用于例如lambdas)。我不知道这是否是现在的情况,但它是一个明显的可能性。


Two question regarding decltype and typeof:

  • Is there any difference between the decltype and typeof operators?
  • Does typeof become obsolete in C++11?

解决方案

There is no typeof operator in c++. While it is true that such a functionality has been offered by most compilers for quite some time, it has always been a compiler specific language extension. Therefore comparing the behaviour of the two in general doesn't make sense, since the behaviour of typeof (if it even exists) is extremely platform dependent.

Since we now have a standard way of getting the type of a variable/expression, there is really no reason to rely on non portable extensions, so I would say it's pretty much obsolete.

Another thing to consider is that if the behaviour is of typeof isn't compatible with decltype for a given compiler it is possible that the typeof extension won't get much development to encompass new language features in the future (meaning it might simply not work with e.g. lambdas). I don't know whether or not that is currently the case, but it is a distinct possibility.

这篇关于decltype和typeof之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆