Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

Please explain peculiar instantiation of class

Please see question in attached file.
peculiar-class-instantiation.txt
0
naseeam
Asked:
naseeam
  • 2
  • 2
2 Solutions
 
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.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now