开发者

Class member access : section 3.4.5, point 2: point from N3290 draft C++

Class member access : section 3.4.5, point 2:

If the id-expression in a class member access (5.2.5) is an unqualified-id, and the type of the object expression is of a class type C, the unqualified-id is looked up in the scope of class C. For a pseudo-destructor call (5.2.4),the unqualified-id is looked up in the context of the complete postfix-expression.

here in the above statement : For a pseudo-destructor call (5.2开发者_高级运维.4),the unqualified-id is looked up in the context of the complete postfix-expression.

can any one explain this in terms of an program (i know about pseudo-destructor call)?


A pseudo-destructor is a destructor-like syntax invoked on a non-class type:

typedef int I;
I x;
x.I::~I();

If this were parsed “naively”, then the parser would see the following tokens:

unqualified-id(x), typename(I), ::, bitwise-negate, typename(I), (, ), ;.

The “bitwise-negate” is a problem because if you just wrote this:

~I();

Then this would form a valid expression with a different semantic. Namely, the same as ~0. Therefore, the expression above has to be parsed differently to account for the pseudo-destructor context.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜