如何正确传递此二维动态数组

时间:2019-04-28 00:39:27

标签: c++ arrays dynamic

我试图传递设置有2d像素图像信息的动态2d数组,但我不断收到数组下标的错误无效类型int [int]。有人可以告诉我或向我展示正确的方法吗?

制作2d数组的地方

main.cpp

      inFS >>row>>col;
      int **p = new int *[row];
       for(int i = 0; i <row; i++){
          p[i] = new int[col];
        }
        for(int i = 0; i < row; i++){
          for(int j = 0; j < col; j++){
            inFS >> p[i][j];
          }
       }
       inFS.close();

passed into the object rotate here

    rotate.selectOption(**p, row, col);

---------------------------------------------------------------
rotate.hpp 
public prototypes 


                void selectOption(int& , int, int);

                void flipHorizontally(int& , int, int);

-----------------------------------------------------------------
rotate.cpp
           void Rotate::selectOption(int &p, int row, int col){
                    flipHorizontally(p, row, col);
there is other stuff in a do while loop along with a switch but here is where it is called from selectOption

      void Rotate::flipHorizontally(int &p, int row, int col){
         cout<<"flipping horizontally"<<endl;

         for(int i = 0; i < row; i++){
            for(int j = 0; j< col; j++){
            int temp = p[i][j];
            p[i][j] = p[i][col-1-j];
            p[i][col-1-j]=temp;
           }
            }
           }

好吧,一旦我知道正确地做到这一点,我就会将新的翻转数组放入输出文件中,但是我无法通过数组传递这个麻烦。

0 个答案:

没有答案