C++ is built around four foundational principles of object-oriented programming: encapsulation, which bundles data and the functions that operate on it together; abstraction, which hides implementation details behind a clean interface; inheritance, which lets new classes derive from existing ones to establish is-a relationships and reuse code; and polymorphism, which lets a single interface represent different underlying types. Classes are the central mechanism for applying these principles. A class is a user-defined type that groups data members and member functions, declared with the class keyword. The closely related struct keyword defines essentially the same kind of type, with the only default difference being access control: class members are private by default, while struct members are public by default. Both can hold methods, constructors, and participate in inheritance.
Access in C++ is governed by three levels. public members are visible everywhere, protected members are accessible to the class itself, its friends, and any derived classes, and private members are restricted to the class and its friends. The default for a class is private, while the default for a struct is public. When the encapsulation of private or protected data must be relaxed for a specific helper, a class can grant access with friend declarations: a friend function is a non-member function declared inside the class with the friend keyword that gains access to non-public members, and a friend class grants the same access to every member of another class, which is useful for tightly coupled types such as iterators over a container. Const correctness is the discipline of marking every value or function that should not change as const. const int x = 5 forbids reassignment, a function declared void foo(const std::string& s) declares a parameter it will not modify, and a member declared int getVal() const promises not to modify the object. Using const consistently prevents accidental mutation and enables compiler optimizations.
The static keyword has several distinct meanings depending on context. A static local variable inside a function persists across calls and is initialized only once. A static class member belongs to the class itself rather than to any object, so all instances share a single copy and it must be defined in exactly one translation unit, as in the line int MyClass::count = 0. A static member function is similarly tied to the class: it has no this pointer and can only access static members, and is called through the class name. Every non-static member function receives an implicit this pointer referring to the object on which it was called; this has type ClassName* const, or const ClassName* inside a const member function. Const member functions, marked with a trailing const, are the only kind that can be called on const objects. To allow internal caches, lazy initialization, or mutexes to be updated without violating that promise, a member may be declared mutable, which exempts it from const-correctness restrictions.