R
REH
Ugh. Just the fact that such a thing is allowed puts me off C++.
It's no different than you allocated memory in C and initializing an
object in it. It just allows it to be done for object's requiring
construction. Container classes make use of it to be able to construct
objects in the container's memory and destroy objects removed from the
container without have to constantly reallocate memory. It makes the
containers implementation more efficient. A C++ vector, for example,
guarantees it will never allocate more memory from the free store, and
long as the vector's capacity is not exceeded. Placement new makes
such a guarantee easy to implement, by being able to construct an
object at a given element of the vector's internal array, and to do so
in a portable way.
There are a lot of things C++ has to improve portability. For example,
unlike C, C++ has a portable mechanism for comparing unrelated
pointers. The next version of the standard will include portable
mechanisms for doing such things as memory fences and atomic
operations.
Of course, I get the feeling that you wouldn't change your opinion
even if it programmed itself while you slept. C is a great language,
but it's not the end-all-be-all of programming. At my job I use all of
C, but I also use a lot of C++ and Ada, plus various other tools that
suit my needs. I don't try to shoehorn every programming problem into
my favorite language. I use what's best (for whatever best means at
the time). One time it meant using VBScript (though I hate the
language), because it was the one scripting language I could guarantee
was one every machine it has to run on and had the necessary features
to do the job. Perl would have been a better choice, if I could have
made the same guarantees.
REH
REH