雁过无痕

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
int x;
decltype(x) 和  decltype((x))    的类型是不一样的。
decltype(x) 和  decltype(*&x)   的类型是不一样的。

decltype(x)的类型是 int
decltype((x)) 和 decltype(*&x)  的类型是 int&

C++11标准:
The type denoted by decltype(e) is defined as follows:
  — if e is an unparenthesized id-expression or an unparenthesized class member
     access (5.2.5), decltype(e) is the type of the entity named by e. If there
     is no such entity, or if e names a set of overloaded functions, the program
     is ill-formed;
  — otherwise, if e is an xvalue, decltype(e) is T&&, where T is the type of e;
  — otherwise, if e is an lvalue, decltype(e) is T&, where T is the type of e;
  — otherwise, decltype(e) is the type of e.
posted on 2012-08-14 21:19 flyinghearts 阅读(1826) 评论(5)  编辑 收藏 引用 所属分类: C++

评论

# re: decltype的小“陷阱” 2012-08-14 21:39 Cheap lace wigs
decltype 这个如果不注意确实容易犯错啊,不错,学习了  回复  更多评论
  

# re: decltype的小“陷阱”[未登录] 2012-08-15 09:10 Chipset
加入thread和一些必要的库也就罢了。弄一堆形式上的写法无非少敲几次键盘,形式上看起来爽点,没有任何实用价值,感觉C++越来越花哨了。  回复  更多评论
  

# re: decltype的小“陷阱”[未登录] 2012-08-15 09:12 Chipset
语法越来越复杂,太多的人不得不浪费太多时间熟悉那些花哨的东西,工业语言是这么进化的吗??C++总会有一天死在这帮家伙们的手里。。。  回复  更多评论
  

# re: decltype的小“陷阱” 2012-08-15 23:26 tb
呵呵 看来大家在这里都容易犯错啊   回复  更多评论
  

# re: decltype的小“陷阱” 2012-08-19 16:13 gbb21
好!  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理