calling constructor when allocating an array

P

Philipp

i think you're trying to do something like this:
int N = 22;
// the ** makes the array of pointer not array of objects
MyClass **pointerArray;

// crerate all the Pointer
pointerArray = new (MyClass*)[N];

// create all the objects
for (int i=0; i< N; i++)
pointerArray = new MyClass(i);


Yes exactly! That's what I wanted to do and after thinking for 5 minutes by
myself I figured it out...
I just was confused that one of the ' * ' is for the array and the second
one is for the actual pointers stored in the array.

Thanks to all of you for your answers.
Phil
 
W

White Wolf

Ron said:
I have no qualms with whether pointerArray is an array of pointer or
pointer to an array. However, it the example given, you HAVE
NEITHER.

Yes, I missed the mistake in the code.
You are destined for trouble if you think pointers and arrays are
synonymous.
They are not. Pointers point to single objects.

I do not think that and I have never said I did.
However my comments were specifically directed at the comment from
attilla
that said that a pointer might be thought of pointing to the first
byte.

Look at the sig Ron. I *am* Attila. With an uppercase A, and pronounced
Atilla. With an uppercase A/ ;-)
This is not true.

Correction: this may not be true.
There's no rquirements that a non-char pointer even be
able to address bytes.

But it is guaranteed that when converted to char* (or unsigned char* or
signed char*) it will point to the first byte of the storage representing
that object.
If people would stop assumingt the entire world is a
freaking
Pentium they'd understand the language a little better.

If people would stop assuming what other people assume we would get less war
and more beer to drink.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top