title: Returning reference to a pointer- C++
body: <p>Consider the following class.</p>
  
  <pre><code>class mapping_items
  {
  public:
  
      mapping_items(){}
  
      void add(const mapping_item* item) {
          items_.push_back( item );
      }
  
      size_t count() const{
          return items_.size();
      }
  
      const mapping_item&amp; find(const std::string&amp; pattern){
          const mapping_item* item = // iterate vector and find item;
          return *item; 
      }
  
  private:
      mapping_items(const mapping_items&amp;); // not allowed
      mapping_items&amp; operator=(const mapping_items&amp;); // not allowed
      std::vector&lt;const mapping_item*&gt; items_;
  };
  </code></pre>
  
  <p>C++ FAQ says,</p>
  
  <blockquote>
    <p>Use references when you can, and
    pointers when you have to.</p>
  </blockquote>
  
  <p>So in the above example, should I return <code>const mapping_item&amp;</code> or <code>const mapping_item*</code> ?</p>
  
  <p>The reason why I chose <code>mapping_item&amp;</code> is because there will be always a default return value available. I will never have null returns. So a reference makes it clear that it can't have nulls. Is this the correct design?</p>