Solved

Please explain peculiar instantiation of class

Posted on 2013-06-12
4
249 Views
Last Modified: 2013-06-12
Please see question in attached file.
peculiar-class-instantiation.txt
0
Comment
Question by:naseeam
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

820 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