title: Class member suddenly becomes inaccessible/non-existent
body: <p>In my main, I am calling a function (<code>func1</code>)in a loop. This function is a member of <code>Class1</code>. I am passing an object (<code>object2</code>) of a different class, <code>Class2</code> to this function. On the first iteration of the loop, the variable <code>var2</code> (member of <code>Class2</code>) is accessible from main, but on the second iteration, it is not. I get an "Access violation reading location" error. Here is what my code looks like:</p>
  
  <p>main.cpp:</p>
  
  <pre><code>#include "Class1.h"
  int main(){
  
      Class2 object2;
      object2.assign_var2();
      Class1 object1;
  
  
      for (int i = 0; i &lt; 2; ++i){
          std::cout &lt;&lt; object2.var[0][0][0] &lt;&lt; std::endl; // Works ONLY on first iteration
          object1.func1(object2)
      }
  }
  </code></pre>
  
  <p>Class2.h:</p>
  
  <pre><code>class Class2{
      ... other variables and functions declared
      public:
      Class2::Class2();
      Class2::~Class2();
      double *** var2;
      void assign_var2();
  }
  </code></pre>
  
  <p>Class2.cpp:</p>
  
  <pre><code>Class2::Class2(){
  
  var2 = new double**[200];
  for (int i = 0; i &lt; 200; ++i) {
      var2[i] = new double*[200];
  
      for (int j = 0; j &lt; 200; ++j){
      var2[i][j] = new double[2];
      }
  }
  
  Class2::~Class2(){
  for (int i = 0; i &lt; 200; ++i){
      for (int j = 0; j &lt; 200; ++j){
          delete [] var2[i][j];
      }
      delete [] var2[i];
  }
  delete [] var2;
  }
  
  void assign_var2(){
  for (int i = 0; i&lt;200; ++i){
      for (int j = 0; j&lt;200; ++j){
  
          var2[i][j][0] = some_number1;
          var2[i][j][1] = some_number2;
      }
  }
  }
  }
  </code></pre>
  
  <p>Class1.h:</p>
  
  <pre><code>#include "Class2.h"
  class Class1{
      ... other variables, functions declared
      public:
      void func1(Class2)
  </code></pre>
  
  <p>}</p>
  
  <p>Class1.cpp:</p>
  
  <pre><code>Class1::func1(Class2 object2){
      int u = object2.var2[1][2][0];
      int v = object2.var2[1][2][1];
  }
  </code></pre>
  
  <p>Side note: If I try and print a different variable instead of <code>var2</code>, it seems to work on the second iteration, so I don't think it's a problem with the object itself.</p>
  
  <p>Thanks in advance!!</p>