I am not asking decltype((x))
, I know how it works.
According to the draft N4687, § 10.1.7.2
4 For an expression e, the type denoted by decltype(e) is defined as follows:
...
(4.2) — otherwise, if e is an unparenthesized id-expression or an unparenthesized class
member access (8.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;
...
And example
struct A { double x; };
const A* a = new A();
decltype(a->x) x3; // type is double
My question is,
a->x
is const double
, but why does x3 is double
? where does the const
go?
BTW, what is decltype(e) is the type of the entity named by e
meaning exactly?
A class member access is either
.
or->
, according to [expr.ref].There is an ambiguity here:
a->x
is both a class member and an object (a member subobject). The important thing to note is thatdecltype(e)
is the type of the entity named bye
. The only kinds of entities that can be named are those that are introduced by declarations (¶5). A member subobject does not have a name in this sense, as it is not declared. That leaves the only other alternative thatdecltype(x->a)
must be the type of the class member (not the object member).