title: C++ what to return for the vector::back() on an empty vector
body: <p>Suppose that I have a class with a vector data member, and a function to get last element of the vector and returns integer. How can I handle the case in this function that vector is empty? what should I return?</p>
  
  <pre><code>class Test
  {
  private:
     std::vector&lt;stack&lt;int&gt;&gt; vec_;
  public:
      void push(int v);
      int GetElement();
  };
  
  stack&lt;int&gt; Test::GetElement()
  {
      if(!vec_.empty())
          return vec_.back();
      else
         // I want to return something that shows me my vector is empty, 
         // So later on I can use this function to instantiate a stack and push to the vector, 
         // if there is none. what should I do in here????
  }
  </code></pre>
  
  <p>Edit: I changed the GetElement() to return a stack*. This way I can return nullptr in case of vector being empty.</p>