Pointer vs. reference return types

You could use a pointer instead of a reference if:

  • Null is a valid return value
  • You dynamically constructed something in the function, and the recipient becomes the owner. (In this case, you might consider returning a smart pointer such as std::unique_ptr or boost::shared_ptr.)

Regardless, you would not want to return either a pointer or a reference to a local variable.

Leave a Comment

tech