Cae*_*sar 10 c++ decltype language-lawyer c++11
我不是问decltype((x)),我知道它是如何工作的.
根据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;
...
Run Code Online (Sandbox Code Playgroud)
例如
struct A { double x; };
const A* a = new A();
decltype(a->x) x3; // type is double
Run Code Online (Sandbox Code Playgroud)
我的问题是,
a->x是const double,但为什么x3是double?在什么地方const去了?
BTW,究竟是什么decltype(e) is the type of the entity named by e意思?
这方面的标准似乎含糊不清.
一个实体是一个值,对象,参考,功能,枚举,类型,类的成员,位字段,模板,模板特,命名空间或参数包.
表达a->x,可以说,仅举构件 x的struct A,其类型double.也可以说相同的表达式命名具有类型的对象const double.这两件事都是实体.规范性文本并未明确表明预期的解释是第一个,它只能从示例中推断出来.