In C++, like in many other languages, we have different ways of expressing the presence or absence of a value. In C++ specifically, we can use any of the following:
Using nullptr to encode absence.
Using a smart pointer (e.g., shared_ptr) which, again, can be tested for presence or absence.
std::optional<T> is a library solution; it can either store a value of type T or std::nullopt if the value is missing.
Suppose we decide to go with the nullptr approach . In this case, let’s imagine that our domain model defines a Person who may or may not have an Address, which, in turn, can ...