0
_classA **_TTT[3];
_TTT[n][_num_ttt[n]] = new _classA(3,5);

May I know what is

_TTT[n][_num_ttt[n]] 

How this dynamic array work?Appreciate if you could provide me an explanation in graphical view how actually the dynamic pointer point to the other and how to form [ ][ ]. Thanks.

3
  • 2
    However that works, it should be killed with fire. Commented Jun 25, 2013 at 7:05
  • @BartekBanachewicz Could you pls tell me why ?this is not the right way to do? Commented Jun 25, 2013 at 7:07
  • C++ provides useful abstractions over raw arrays that allow you to spell the clearer syntax and more precise semantics. Commented Jun 25, 2013 at 7:14

2 Answers 2

2

_TTT is a static array of three pointer-to-pointers-to-classA. _TTT[n] gives us one of the pointer-to-pointers, _num_ttt[n] is just another index (like i would be) so, _TTT[n][i] finally resolves to the i'th pointer to _classA inside the n'th array of pointers. It is then assigned with the new on the right side.

Sign up to request clarification or add additional context in comments.

Comments

1

Czech this Tutorial on MultiDim Arrays, it might bring some light into that dark room of yours.

But basically you just store an array of arrays. Arrays are nothing more than an collection of pointers to data points. In C++ you can have pointers pointing to other pointers which then again point to the value.

Rather don't use it, except if you really need it, as many programmers really get confused by it quickly. One Application would be a Map or Picture, where you need X/Y coordinates, but except that you can do things simpler by other methods.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.