this

suggest change

Within a member function of a class, the keyword this is a pointer to the instance of the class on which the function was called. this cannot be used in a static member function.

struct S {
    int x;
    S& operator=(const S& other) {
        x = other.x;
        // return a reference to the object being assigned to
        return *this;
    }
};

The type of this depends on the cv-qualification of the member function: if X::f is const, then the type of this within f is const X*, so this cannot be used to modify non-static data members from within a const member function. Likewise, this inherits volatile qualification from the function it appears in.

this can also be used in a brace-or-equal-initializer for a non-static data member.

struct S;
struct T {
    T(const S* s);
    // ...
};
struct S {
    // ...
    T t{this};
};

this is an rvalue, so it cannot be assigned to.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


keywords:
* class
* float
* bool
* void
* char
* short
* long
* double
* int
* enum
* if
* do
* else
* true
* false
* const
* for
* goto
* struct
* case
* catch
* return
* signed
* static
* this
* switch
* throw
* try
* break
* union
* asm
* sizeof

Table Of Contents
8 Arrays
11 Loops
14 keywords
39 Streams
51 Unions
56 Lambdas
60 SFINAE
62 RAII
67 Sorting
84 RTTI
87 Scopes
104 Profiling
107 Recursion
117 Iteration
125 Alignment
134 Semaphore
136 Debugging
139 Mutexes
142 decltype