Ch 11 · Working with Classes · C++
Topic 11 of 13 in C++ — Complete Tutorial (Beginner) — 2 lessons.
The this Pointer & Member Functions
Inside a class method, this is a pointer to the current object. It lets you tell apart a member variable from a parameter that share the same name, written this->name = name. Methods can read and update the object's members, and call other methods of the same object. Organising behaviour inside the class keeps related data and code together.
Many Objects Together
The power of classes shows when you store many objects in a vector and loop over them — a class list, a product catalogue. Each object keeps its own data while sharing the same methods. This combination of a class plus a container is one of the most common and powerful patterns in C++.