how to return two dimensional char array c++?

前端 未结 8 2129
攒了一身酷
攒了一身酷 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 16:08

    I would really recommend using STL vector<> or boost/multi_array containers for this.

    If you must use arrays, then I would recommend using a typedef to define the array.

    typedef char[16][10] TBoard;
    

    You could also return

     char**
    

    ...but then you would need to typecast it to the correct size in order to index it correctly. C++ does not support dynamic multiple dimension arrays.

    Also as others have suggested you can't return an object on the stack (i.e., local variable)

提交回复
热议问题