title: C++ Console Application1.exe has triggered a breakpoint
body: <p>when I try to set </p>
  
  <pre><code>cub.SetArray(cube);
  </code></pre>
  
  <p>I get an error </p>
  
  <pre><code>Console Application1.exe has triggered a breakpoint 
  </code></pre>
  
  <p>What I'm doing wrong? When I try to debug <code>cub -&gt; cubesarray</code> I get size -842150451. I don't understand why.Here's my all code</p>
  
  <pre><code>class Cube{
  public:
      static const int Change_ARRAY = 5;
  
  private:
      string color;
      int size;
      int *walls;
      int n; // current size of array
      int maximumsize; // maximum size of array
      void Increase(int many);
  public:
      Cube(int maximumsize = 0);
      ~Cube();
      void SetWalls(int wall);
      void SetColor(string color);
      void SetSize(int size);
  
      string GetColor(){return color;}
      int GetWalls(int i){return walls[i];}
      int GetSize(){return size;}
  
      int GetN(){return n;}
  };
  
  Cube::Cube(int maximumsize):n(0), maximumsize(maximumsize), size(size), walls(NULL){
      if(maximumsize &gt; 0){
          walls = new int[maximumsize];
      }
  }
  
  Cube::~Cube(){
      if(walls){
          delete [] walls;
      }
  }
  
  void Cube::Increase(int many){
      if(many &gt; maximumsize){
          int *newest = new int[many];
          for(int i=0; i&lt;n; i++)
              newest[i] = walls[i];
          delete [] walls;
          walls = newest;
          maximumsize = many;
      }else if( many &lt; maximumsize){
          int *newest = new int[many];
          for(int i=0; i&lt;many; i++)
              newest[i] = walls[i];
          delete [] walls;
          walls = newest;
          n = maximumsize = many;
      }
  }
  
  void Cube::SetWalls(int wall){
      if(n == maximumsize) Increase(n + Change_ARRAY);
      walls[n] = wall;
      n++;
  }
  
  void Cube::SetColor(string color){
      this-&gt;color = color;
  }
  
  void Cube::SetSize(int size){
      this-&gt;size = size;
  }
  
  class CubesArray{
  public:
      static const int Change_Array = 5;
  private:
      Cube *cubesarray;
      int currentsize; // current size of array
      int maxsize; // maximumsize
      void Change (int kk);
  public:
      CubesArray(int maxsize = 1);
      ~CubesArray();
  
      void SetArray(Cube c);
      Cube GetArray(int ind){return cubesarray[ind];}
      int GetCsize(){return currentsize;}
  };
  
  CubesArray::CubesArray(int maxsize):cubesarray(NULL), currentsize(0), maxsize(maxsize){
      if(maxsize &gt; 0){
          cubesarray = new Cube[maxsize];
      }
  }
  
  CubesArray::~CubesArray(){
      if(cubesarray){
          delete [] cubesarray;
      }
  }
  
  void CubesArray::Change(int kk){
      if(kk &gt; maxsize){
          Cube *newarr = new Cube[kk];
          for(int i=0; i&lt;currentsize; i++)
              newarr[i] = cubesarray[i];
          delete [] cubesarray;
          cubesarray = newarr;
          maxsize = kk;
      }if(kk &lt; maxsize){
          Cube *newarr = new Cube[kk];
          for(int i=0; i&lt;kk; i++)
              newarr[i] = cubesarray[i];
          delete [] cubesarray;
          cubesarray = newarr;
          currentsize = maxsize = kk;
      }
  }
  
  void CubesArray::SetArray(Cube cub){
      if(currentsize = maxsize) Change(currentsize + Change_Array);
      cubesarray[currentsize] = cub;
      currentsize++;
  }
  
  void Read(CubesArray &amp; cub);
  
  int main(){
      CubesArray cub;
  
      Read(cub);
  
      system("pause");
      return 0;
  }
  
  void Read(CubesArray &amp; cub){
      string color;
      int size;
      int i=0;
      Cube cube;
      ifstream fd(Data);
      while(!fd.eof()){
          fd &gt;&gt; color &gt;&gt; size;
          cube.SetSize(size);
          cube.SetColor(color);
          cout &lt;&lt; cube.GetColor() &lt;&lt; " " &lt;&lt; cube.GetSize() &lt;&lt; " ";
          while(fd.peek() != '\n' &amp;&amp; !fd.eof()){
              int w;
              fd &gt;&gt; w;
              cube.SetWalls(w);
              cout &lt;&lt; cube.GetWalls(i) &lt;&lt; " ";
              cub.SetArray(cube); // when I set cube to cub I get this error!!!
              i++;
          }
          cout &lt;&lt; endl;
          fd.ignore();
      }
  }
  </code></pre>