There are three cases that I can think of:
If you just want to pass a pointer to the current class:
class B;
struct A {
B* parent_;
A(B* parent) : parent_(parent) {}
};
struct B {
A* a;
B() : a(new A(this)) {}
};
In a constructor or member function, where an element is obscured by an argument:
struct A {
int a;
void set_a(int a) { this->a = a; }
};
Here, the member variable "a" is obscured by the argument "a", therefore it is this->used to access the element instead of the argument.
( , , )
template <class T>
struct A {
int a;
};
template <class T>
struct B : public A<T> {
int f() { return this->a; }
}
a , B B, T. this-> this, this , a , f().
return A::a return this->a, , , this-> . - - , , .