You could look into Boost.Optional:
struct Person
{
std::string Name;
DateTime Birth;
boost::optional<DateTime> Death;
//...
};
- Your
Death
is “uninitialised” at first. - You can then assign a value to it with
=
, likeDeath = myDateTime
. - When
Death.is_initialized()
, you can useDeath.get()
. - Uninitialise it again with
Death.reset()
.
For simple cases like this, though, it’s usually considered more coherent to just pick your own blatant sentinel value like, say, a DateTime
of “0000-00-00 00:00:00”.