how to return two dimensional char array c++?

前端 未结 8 2126
攒了一身酷
攒了一身酷 2020-12-03 15:23

i ve created two dimensional array inside a function, i want to return that array, and pass it somewhere to other function..

char *createBoard( ){  
  char          


        
8条回答
  •  离开以前
    2020-12-03 15:46

    The best approach is create a board class and make the ctreateBoard function its constructor:

    class Board {
      private:
       char mSquares[16][10];
    
       public:
        Board() {
            for(int i=0; i<16;i++){
            for( int j=0;j<10;j++){   
                    mSquares[i][j]=201;
            }       
        }
    
       // suitable member functions here
     };
    

    For information on how to use such a class, there is no substitute for reading a good book. I strongly recommend Accelerated C++ by Andrew Koenig and Barbra Moo.

提交回复
热议问题