Please explain peculiar instantiation of class

Please see question in attached file.
peculiar-class-instantiation.txt
LVL 1
naseeamAsked:
Who is Participating?
 
jkrCommented:
The line

contArr = new ContainerObject * [totalCapacity];

Open in new window


looks a bit confusing, but if you break that down for readability (and consider the rest of the code), it is just allocating an array of pointers, i.e.

contArr // declared as 'ContainerObject **'
 = new 
ContainerObject * // the space makes this confusing
[totalCapacity]; // size of the array

Open in new window

0
 
naseeamAuthor Commented:
Please confirm that class ContainerObject is not getting instantiated in the following statement:

contArr = new ContainerObject* [totalCapacity];
0
 
jkrCommented:
No, the class itself isn't instantiated in that line. What is done here is that an array of the size 'total'Capacity' is allocated which consist of pointersto 'ContainerObject', i.e. 'ContainerObject*'. No single 'ContainerObject' constructor will be called
0
 
naseeamAuthor Commented:
very well short explanation.  To the point.  The quesetion got answered.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.