A shot into new (pun!) territory for me.
Here (way down at the bottom) it states,Since placement new doesn't allocate any memory, it's an error to delete the object created by it.For the time being I've been going with this method.ADVICE: Don't use this "placement new" syntax unless you have to. Use it only when you really care that an object is placed at a particular location in memory. For example, when your hardware has a memory-mapped I/O timer device, and you want to place a Clock object at that memory location.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
>^^^does that mean the array size is 100 and the first element is equal to 0?
An array of size 100 and all elements are initialized to 0. If you privide an initializer list and there aren't enough values, all remaining elements are initialized to the default value T() where T is the type of the array.
>If so, does that mean you array will look like this a[0, 100, 200,..., 99,000]?
Try it and see.
>^^^Does this mean p points to array a and the array's size equals 5?
Yes.
>why isn't the output 0 100 200 300 400 instead of 0 10 20 30 40?
It is. The comment and code don't match.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>Hmmm...you lost me.
Joy.
>Where did this default value T() where T is the type of the array stuff come from?
It's a generic way of saying that all of the ints are set to 0. However, you can do this:
int x = int();
And set x to the default value of an int, or 0. To make the description generic, one would say T() instead of int() where T refers to an arbitrary, but unknown type.
>I don't own a computer remember?
That makes teaching you C++ a reall pain in the butt. There are just some things you have to experiment with to understand.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401