dot (.) operator in C++ is used to access members (data and functions) of a class, struct, or union through an object. It allows direct interaction with an object’s components.
- The dot (.) operator accesses member variables and functions using objects (not pointers) and is used for direct member access.
- It has very high precedence in C++, just below brackets, and shares the same level with the arrow (->) operator.
- The arrow (->) operator works similarly but accesses members through pointers instead of objects.
- The dot (.) operator cannot be overloaded, and attempting to do so causes compile-time errors.
Syntax
variable_name.member;
- variable_name: It's an instance of a class, structure, or union.
- member: member variables or member functions associated with the created object, structure, or union.