Best way to represent Nullable member in C++? [duplicate]

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 =, like Death = myDateTime.
  • When Death.is_initialized(), you can use Death.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”.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)