title: Segmentation Fault when accessing second element in obj vector using pointer
body: <p>please take a look at this code:</p>
  
  <pre><code>#include &lt;vector&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  class A
  {
      private:
          string contentA;
  
      public:
          A(){ contentA = ""; };
          A( string setContent ){ contentA = setContent; };
          virtual string printContent(){ return contentA; };
  };
  
  class B: public A
  {
      private:
          string contentB;
  
      public:
          B( string setContent ){ contentB = setContent; };
          virtual string printContent(){ return contentB; };
  };
  
  int main()
  {
  
      vector&lt;A*&gt; aPointer;
      vector&lt;B&gt; bVector;      
  
      B b1("b1");
      //store b1 obj in bVector
      bVector.push_back( b1 );
      //store the current(last) obj address to aPointer for access later
      aPointer.push_back( &amp;bVector.back() );
  
  //    B b2("b2");
  //    bVector.push_back( b2 );
  //    aPointer.push_back( &amp;bVector.back() );
  
      for( vector&lt;A*&gt;::iterator it = aPointer.begin(); it != aPointer.end(); it++ )
      {
          cout &lt;&lt; (*it)-&gt;printContent() &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>aPointer will store pointer to the element of B vector.</p>
  
  <p>May i ask why does it has a segmentation fault when i access the 2nd element in my B vector in the for loop?</p>
  
  <p>I've hex in and it will work fine again.</p>