Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

decltype and parentheses

I don't understand the last line of the example on page 148 of the FCD (§7.6.1.2/4):

const int&& foo(); int i; struct A { double x; }; const A* a = new A(); decltype(foo()) x1 = i;     // type is const int&& decltype(i) x2;             // type is int decltype(a->x) x3;          // type is double decltype((a->x)) x4 = x3;   // type is const double& 

Why do the parentheses make a difference here? Shouldn't it simply be double like in the line above?

like image 903
fredoverflow Avatar asked Jun 22 '10 23:06

fredoverflow


1 Answers

Just above that example, it says

  • if e is an unparenthesized id-expression or a class member access (5.2.5), decltype(e) is the type of the entity named by e.
  • if e is an lvalue, decltype(e) is T&, where T is the type of e;

I think decltype(a->x) is an example of the "class member access" and decltype((a->x)) is an example of lvalue.

like image 192
Cubbi Avatar answered Oct 11 '22 19:10

Cubbi