Solved

Please explain peculiar instantiation of class

Posted on 2013-06-12
4
254 Views
Last Modified: 2013-06-12
Please see question in attached file.
peculiar-class-instantiation.txt
0
Comment
Question by:naseeam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 39241560
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
 
LVL 1

Author Comment

by:naseeam
ID: 39241676
Please confirm that class ContainerObject is not getting instantiated in the following statement:

contArr = new ContainerObject* [totalCapacity];
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 500 total points
ID: 39241690
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
 
LVL 1

Author Closing Comment

by:naseeam
ID: 39241712
very well short explanation.  To the point.  The quesetion got answered.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question