title: c++ How to return a vector by reference?
body: <p>I'm a c++ student and could use some help with understanding and doing this part of my assignment.</p>
  
  <p>I have a vector of <code>SalesItem</code> objects:</p>
  
  <pre><code>class Invoice
  {
  public:
      //blabla
      vector&lt;SalesItem&gt; *getSalesItems(); //code provided by the assignment.
  private:
  {
      //blabla
      vector&lt;SalesItem&gt; salesItems;
  };
  </code></pre>
  
  <p>and I need to return that vector as a reference:</p>
  
  <pre><code>void Invoice::getSalesItems() //error on this line. Code provided by assignment.
  {
      return salesItems; //error on this line.
  }
  </code></pre>
  
  <p>Now, I know that the things that are giving me errors are obviously wrong, I don't even have any pointers or references in there. I'm posting those few lines of code just as an example of what I would like to see (or more realistically, what makes sense to me.)</p>
  
  <p>I want a get function that works like other get functions for types like int or string, except this one has to return by reference (as required by the assignment.)</p>
  
  <p>Unfortunately, my understanding of vectors and references is not up to merit for this problem, and I do not have any educational resources that can help me on this. If someone could please help me understand what to do, I would greatly appreciate it.</p>
  
  <p>Any extra information will be gladly given.</p>