template <class Base>
struct Derived : Base
{
Derived()
{
// Without "this->", the compiler must assume that foo_ is
// a non-member variable, because it can't see it in the current
// scope during that compilation stage. With this->, it now knows
// that it is a member variable from the inherited base class.
this->foo_ = true;
}
};
void Foo::bar(int x) {
this->x = x;
}
void Foo::bar(int otherX) {
x = otherX;
}
I've seen some C++ that uses "this" anytime it accesses a property. Does that protect the author from some
sort of folly?
An example might be: