[expr.prim.this] (original) (raw)

7 Expressions [expr]

7.5 Primary expressions [expr.prim]

7.5.2 This [expr.prim.this]

The keyword this names a pointer to the object for which a non-static member function ([class.this]) is invoked or a non-static data member's initializer ([class.mem]) is evaluated.

It shall not appear before the optional cv-qualifier-seq and it shall not appear within the declaration of a static member function (although its type and value category are defined within a static member function as they are within a non-static member function).

[Note 1:

This is because declaration matching does not occur until the complete declarator is known.

— _end note_]

[Note 2:

Class members declared later are not visible.

[Example 1: struct A { char g();template<class T> auto f(T t) -> decltype(t + g()) { return t + g(); } };template auto A::f(int t) -> decltype(t + g()); — _end example_]

— _end note_]

The expression this shall not appear in any other context.

[Example 2: class Outer { int a[sizeof(*this)]; unsigned int sz = sizeof(*this); void f() { int b[sizeof(*this)]; struct Inner { int c[sizeof(*this)]; };} }; — _end example_]