This is more of a theoretical question, and a non-serious one at that, but one I couldn't find an answer to online that I'm moreso just curious about.
If I were to create some class in C++ (we'll just call it Object
) and made a dynamic array of this object type:
Object* objectArray = new Object[someSize];
Would there ever be some instance where I would want to make the elements inside the array dynamic as well?
I would imagine not, since this array already exists on the heap and there would be no reason to therefore specify that the elements inside should also be on the heap, if I understand how dynamic arrays work correctly.
Object** objectArray = new Object*[someSize];
which would let you do things like:
objectArray[0] = new Object(*parameters*);
I know this question is a bit nonsense, but I was intrigued if there were any use-cases for this type of thing. I couldn't find any similar posts on my own.
Still, if someone has asked this, feel free to just redirect me to that page, as I had no luck finding it myself.