3D array C++ using int [] operator

后端 未结 7 1876
长发绾君心
长发绾君心 2020-12-15 09:03

I\'m new to C/C++ and I\'ve been cracking my head but still got no idea how to make an \"structure\" like this

\

7条回答
  •  一生所求
    2020-12-15 09:07

    OK let us take your beginnings

    int ***sec = new int**[x]; 
    

    sec is now an array of int**s of length x, so now I am just going to focus on making the zeroeth element be what you want

    sec[0] = new int*[y];
    

    Now sec[0] points to array of int*s of length y, now just need to get the last bit of the tree done, so

    sec[0][0] = new int[z];
    

    And finally to get it to the form in your diagram

    sec[0][0][z-1] = 0;
    

    This does seem a little like a homework question, make sure you actually understand the answer and why it works.

提交回复
热议问题