title: Pass object array into member function
body: <p>Here is the class defination:</p>
  
  <pre><code>class Unit
  {
      public:
       Unit();
       ~Unit();
       void set_unit(int a);
       void modify_flag(Unit&amp;);
       void modify_array(Unit array[], int len);  // ?? The problem
       int show_unit();
  
      private:
       int ai;
  
  };
  </code></pre>
  
  <p>And the implementation of the member functions:</p>
  
  <pre><code>void Unit::set_unit(int a)
  {
       ai = a;
  }
  
  void Unit::modify_flag(Unit&amp; u)
  {
       u.set_unit(20);
  }
  
  void Unit::modify_array(Unit array[], int len)  // ?? The problem
  {
       for (int i = 0; i &lt; len; ++i)
       {
          modify_flag(array[i]);
          array[i].modify_array(array, len);
       }
  }
  
  int Unit::show_unit()
  {
      return ai;
  }
  </code></pre>
  
  <p>And finally the main code:</p>
  
  <pre><code>int main(int argc, char const *argv[])
  {
      int len = 10;
      Unit* array = new Unit[len];
  
      for (int i = 0; i &lt; len; ++i)
      {
          array[i].set_unit(0);
      }
  
      array[5].modify_array(array,len);  // ?? The problem
  
  
      for (int i = 0; i &lt; len; ++i)
      {
          cout &lt;&lt; array[i].show_unit() &lt;&lt; endl;
      }
  
      delete [] array;
  
      return 0;
  }
  </code></pre>
  
  <p>I passed an array of objects into the member function of the class as the parameter, but it aborted suddenly.  I have checked my code many times to make sure the counter did not accumulate over the array length. Therefore, I think there must be something wrong with the object array as the parameter, but I could not figure it out.  What happened with my code ?? </p>