CKTIS / C++
Member access operator (.)
The . operator accesses a member of a class, struct, or union object. It lets you read and modify data members and call member functions. It also works through an object reference, but does not replace -> for a pointer.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
object.member
object.member_function(arguments)The expression object.member selects a named member of an object; object.member_function(arguments) calls a member function. A reference also allows .. For an ordinary pointer, use ptr->member, meaning (*ptr).member.
The . operator does not bypass public, protected, or private access control. Members of a struct are public by default, whereas members of a class are private by default. The . operator itself cannot be overloaded.
In the example, ref denotes the same object as counter: ref.increment() increases value from 4 to 5, and counter.value += 2 produces 7.
This entry targets C++23. The supplied source is an evolving working draft, not a frozen C++23 edition; later extensions are not covered here.
Examples
#include <iostream>
struct Counter {
int value;
void increment() {
++value;
}
};
int main() {
Counter counter{4};
Counter& ref = counter;
ref.increment();
counter.value += 2;
std::cout << counter.value << '\n';
}
Result
7
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.