title: c++ different error depends on whether or not I'm printing a variable
body: <p><strong>Preface</strong><br>
  This is probably a bad question but I'm truly hopeless here. I know that I my question is a bad one since it is highly specific to my problem but I'll try to describe the problem the best and most general way I can...</p>
  
  <p><strong>Some background</strong><br>
  In my code, I have a data structure named <code>bead</code> which holds, among other an integer variable named <code>LID</code>. I also have a data structure named <code>lipid</code> which holds, among others, three pointers to (three different) <code>bead</code>s. The <code>lipid</code>s are held in a <code>vector&lt;lipid*&gt;</code> variable named <code>lipids</code> and <code>bead</code>'s <code>LID</code> variable is equal to the position of the appropriate <code>lipid</code> in <code>lipids</code> +1. </p>
  
  <p>During my (Monte Carlo - MC) simulation, I choose a random number between 0 and 999 and change appropriate <code>lipid</code>. I then test the change using a function named <code>calcEnergy</code> which accept the <code>lipid</code>'s <code>bead</code> pointers one at a time as it's input (named <code>mb</code>). </p>
  
  <p><strong>The problem</strong><br>
  I got a bad allocation error after I have picked <code>lipids</code> position number 261. I have tried to find why does that happen so I have typed:</p>
  
  <pre><code>if(mb-&gt;LID ==261){
    printf("something");
  }
  </code></pre>
  
  <p>when I tried this, The simulation stopped (segmentation fault) when the program have picked <code>lipids</code> position number 132. So, I tried to see why is that and printed to the screen the <code>LID</code> of each <code>bead</code> I have sent using <code>printf()</code>. Now the program survive the 132 <code>lipid</code> and crushes on the next <code>lipid</code>.</p>
  
  <p>I am absolutely clueless about the cause of why does the program crashes when I try to read a variable which I know it's valid. </p>
  
  <p>Once again, I know this is a long shot but I have now other idea...</p>
  
  <p>Thanks. </p>