473,396 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Initializing an array of objects allocated dynamically

DK
Is there any pointer analog to this code (adapted from the FAQ):
someclass Objects[5] = { someclass(1), someclass(2), someclass(3),
someclass(4), someclass(5) }; Also, does the above code require the
copy constructor and/or assignment operator to be public? Considering
the fact that someclass has only parameterized constructors (so
creating someclass *pObjects = new someclass[5]; is not an option)?
The idea behind this is that I want to create a class which is
immutable and non-copyable after construction. Hence I don't want to
make the copy constructor and operator = public.

Mar 21 '07 #1
1 1662
On Mar 21, 2:35 pm, "DK" <divyekap...@gmail.comwrote:
Is there any pointer analog to this code (adapted from the FAQ):
someclass Objects[5] = { someclass(1), someclass(2), someclass(3),
someclass(4), someclass(5) }; Also, does the above code require the
copy constructor and/or assignment operator to be public? Considering
the fact that someclass has only parameterized constructors (so
creating someclass *pObjects = new someclass[5]; is not an option)?
The idea behind this is that I want to create a class which is
immutable and non-copyable after construction. Hence I don't want to
make the copy constructor and operator = public.
Do you mean something like:

class someclass
{
someclass& operator=( const someclass& );
someclass( const someclass& );
public:
someclass(int) {}
};

someclass *Objects[] =
{
new someclass(1),
new someclass(2),
new someclass(3)
};

or

auto_ptr<someclassObjects[] =
{
auto_ptr<someclass>( new someclass(1) ),
auto_ptr<someclass>( new someclass(2) ),
auto_ptr<someclass>( new someclass(3) )
};

Cheers! --M

Mar 21 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
9
by: pvinodhkumar | last post by:
The number of elemets of the array, the array bound must be constant expression?Why is this restriction? Vinodh
7
by: masood.iqbal | last post by:
I am having lots of trouble getting a simple program that initializs a dynamically allocated 2D array to work. My 2D array is not getting initialized properly, and additionally I am getting a...
2
by: songfire | last post by:
Hi everybody! Just wondering if it is possible to point to variables in the heap. For example, is this okay? int * ptr_to_DAIA; // pointer to dynamically allocated integer array ptr_to_DAIA =...
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
19
by: Tom Jastrzebski | last post by:
Hello, I was just testing VB.Net on Framework.Net 2.0 performance when I run into the this problem. This trivial code attached below executed hundreds, if not thousand times faster in VB 6.0...
7
by: Jo | last post by:
Hi, How can i differentiate between static and dynamic allocated objects? For example: void SomeFunction1() { CObject *objectp = new CObject; CObject object;
7
by: James Kanze | last post by:
On Apr 10, 4:06 pm, Jerry Coffin <jcof...@taeus.comwrote: Just a note, but in all of these languages, *all* objects are dynamically allocated. I wonder if this isn't more what caused you...
25
by: biplab | last post by:
Hi all, I am using TC 3.0..there if I declare a integer array with dimension 162*219...an error msg saying that too long array is shown....what should I do to recover from this problem???
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.