pointers - Enforce NULL checking in c++ -


my method can return kind of pointer ( example boost::shared_ptr ) , pointer may null. there way enforce users of code check, if empty or not ?

some example of such things - scals's option container, may boost has boost::option ?

you can following:

  • return smart pointer type throws exception if accessed , set null.
  • throw exception instead of returning null pointer
  • return std::optional (or boost::optional) expresses intent (i.e. "value may missing") better pointer

Comments

Popular posts from this blog

arrays - PHP Shopping Cart Variable and Object errors -

mysql - java.sql.SQLException Parameter index out of range (1 > number of parameters, which is 0) -