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

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

how to receive file in java(servlet/jsp) -