Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 检测到堆损坏? void角度(int**&twoDArray,int numRows); 无效打印三角形(整数**2达雷,整数numRows); 空洞生长方形(整数**和两个达雷,整数); void printSquare(int**&twoDArray,int numRows); 使用名称空间std; int main(int argc,字符**argv){ srand((无符号整数)时间(NULL)); int**twoDArray; int numRows=10; 角度(两个达雷,numRows); cout_C++_Visual Studio_Multidimensional Array_Heap Corruption - Fatal编程技术网

C++ 检测到堆损坏? void角度(int**&twoDArray,int numRows); 无效打印三角形(整数**2达雷,整数numRows); 空洞生长方形(整数**和两个达雷,整数); void printSquare(int**&twoDArray,int numRows); 使用名称空间std; int main(int argc,字符**argv){ srand((无符号整数)时间(NULL)); int**twoDArray; int numRows=10; 角度(两个达雷,numRows); cout

C++ 检测到堆损坏? void角度(int**&twoDArray,int numRows); 无效打印三角形(整数**2达雷,整数numRows); 空洞生长方形(整数**和两个达雷,整数); void printSquare(int**&twoDArray,int numRows); 使用名称空间std; int main(int argc,字符**argv){ srand((无符号整数)时间(NULL)); int**twoDArray; int numRows=10; 角度(两个达雷,numRows); cout,c++,visual-studio,multidimensional-array,heap-corruption,C++,Visual Studio,Multidimensional Array,Heap Corruption,WhozCraig在上面的评论中发现了它 yWhozCraig在上面的评论中发现了它 y a)你在哪里删除[]-ing分配的内容?向下滚动代码,我在旁边放了一个箭头。这还不是全部。抱歉听起来很刺耳,但如果你不能正确使用原始指针,请使用std::vector。这也使你当前的任务(调整大小等)更容易解决。a)你的删除[]在哪里-对分配的东西进行分类?向下滚动代码,我在旁边放了一个箭头。这还不是全部。很抱歉听起来很刺耳,但是如果您不能正确使用原始指针,请使用std::vector。这也使您当前的任

WhozCraig在上面的评论中发现了它


  • yWhozCraig在上面的评论中发现了它


    • y a)你在哪里删除[]-ing分配的内容?向下滚动代码,我在旁边放了一个箭头。这还不是全部。抱歉听起来很刺耳,但如果你不能正确使用原始指针,请使用std::vector。这也使你当前的任务(调整大小等)更容易解决。a)你的删除[]在哪里-对分配的东西进行分类?向下滚动代码,我在旁边放了一个箭头。这还不是全部。很抱歉听起来很刺耳,但是如果您不能正确使用原始指针,请使用std::vector。这也使您当前的任务(调整大小等)更容易解决。
      
      void allocateTriangle(int ** & twoDArray, int numRows);
      
      void printTriangle(int ** twoDArray, int numRows);
      
      void growToSquare(int ** & twoDArray, int numRows);
      
      void printSquare(int ** & twoDArray, int numRows);
      
      using namespace std;
      
      int main(int argc, char ** argv){
      
          srand((unsigned int)time(NULL));
      
          int ** twoDArray;
          int numRows = 10;
          allocateTriangle(twoDArray, numRows);
          cout << "******* Triangle array *******" << endl;
          printTriangle(twoDArray, numRows);
          growToSquare(twoDArray, numRows);
          cout << "******* Sqaure array *******" << endl;
          printSquare(twoDArray, numRows);
      
          return 0;
      }    
      
      void allocateTriangle(int ** & twoDArray, int numRows) {
          twoDArray = new int*[numRows];
      
          for (int x = 0; x < numRows; x++){
              twoDArray[x] = new int[x];
              for (int y = 0; y <= x; y++){
                  twoDArray[x][y] = rand() % 100;
              }
          }
      }
      void printTriangle(int ** twoDArray, int numRows){
          for (int x = 0; x < numRows; x++){
              for (int y = 0; y <= x; y++){
                  cout << setw(5);
                  cout << twoDArray[x][y];
              }
          cout << endl;
          }
      }
      
      void growToSquare(int ** & twoDArray, int numRows) {
      
          for (int x = 0; x < numRows; x++){
              int *tempArray = new int[x];
              *tempArray = *twoDArray[x];
      -->     delete [] twoDArray[x];
              twoDArray[x] = new int[numRows];
      
              for (int y = 0; y < numRows; y++){
                  if (y <= x)
                      twoDArray[x][y] = tempArray[y];
                  else
                      twoDArray[x][y] = rand() % 100;
              }
          }
      }
      void printSquare(int ** & twoDArray, int numRows){
          for (int x = 0; x < numRows; x++){
              for (int y = 0; y <= numRows; y++){
                  cout << setw(5);
                  if (y <= x)
                      cout << twoDArray[x][y];
                  else if (y - 1 == x) 
                      cout << " ";
                  else
                      cout << twoDArray[x][y - 1];
              }
              cout << endl;
          }
      }
      
      void allocateTriangle(int ** & twoDArray, int numRows) {
          twoDArray = new int*[numRows];
      
          for (int x = 0; x < numRows; x++){
              twoDArray[x] = new int[x];
              for (int y = 0; y <= x; y++){
                  twoDArray[x][y] = rand() % 100;
              }
          }
      }
      
          twoDArray = new int*[1];
      
              twoDArray[0] = new int[0];
      
                  twoDArray[0][0] = rand() % 100;
      
      void allocateTriangle(int ** & twoDArray, int numRows)
      {
          twoDArray = new int*[numRows];
          for (int x = 0; x < numRows; x++)
          {
              twoDArray[x] = new int[x+1]; // NOTE: size
              for (int y = 0; y <= x; y++)
                  twoDArray[x][y] = rand() % 100;
          }
      }
      
      void printTriangle(int ** twoDArray, int numRows)
      {
          for (int x = 0; x < numRows; cout << endl, ++x)
              for (int y = 0; y <= x; y++)
                  cout << setw(5) << twoDArray[x][y];
      }
      
      void growToSquare(int ** & twoDArray, int numRows)
      {
          for (int x = 0; x < numRows; x++)
          {
              int *tempArray = new int[numRows];
              for (int y=0; y<=x; ++y)
                  tempArray[y] = twoDArray[x][y];
              for (int y=x+1; y<numRows; ++y)
                  tempArray[y] = rand() % 100;
              delete [] twoDArray[x];
              twoDArray[x] = tempArray;
          }
      }
      
      void printSquare(int ** & twoDArray, int numRows)
      {
          for (int x = 0; x < numRows; cout << endl, ++x)
              for (int y = 0; y < numRows; y++)
                  cout << setw(5) << twoDArray[x][y];
      }
      
      ******* Triangle array *******
         80
         80    1
         45   93   28
         19   96   90    7
         38   70   23   26   98
         97   26   98   48   37   97
         77   25   43    0   28   84   90
         95   78   48   16   23   30   14   64
         14   29   83   60    7   83   14   77   94
         79    1   43   55   22   14   80   34   40   53
      ******* Sqaure array *******
         80   10   62   17   62   94   62   47   87    3
         80    1   56   67   56   91   85   51   25    8
         45   93   28    9   42   57   95   56   19   42
         19   96   90    7   46   67   42   77   53   73
         38   70   23   26   98   53   22   34   69    3
         97   26   98   48   37   97    8   18   53   55
         77   25   43    0   28   84   90    7   82   43
         95   78   48   16   23   30   14   64   94   33
         14   29   83   60    7   83   14   77   94   75
         79    1   43   55   22   14   80   34   40   53