Re: A few minor questions
On May 19, 6:28 pm, "Alf P. Steinbach" <al...@start.no> wrote:
* blargg:
Jeff Schwab wrote:
Alf P. Steinbach wrote:
* Jeff Schwab:
[...]
It's not only a lack of clean syntax. How would you
directly call a constructor? Given something like:
auto std::string s;
The constructor is called by the system on your behalf, but
so is the destructor. Saying this is a "constructor call"
is no more meaningful than saying it's a "destructor call."
And so is space allocated and deallocated for the object.
Even simply using placement new involves extra machinery,
for example if creating a Derived object and the Derived
constructor throws, the compiler will then call the Base
destructor, then placement delete. That's a lot more than
simply calling the constructor,
A placement new invocation is a little more than a direct
constructor call, yes, as I've already pointed out in this
thread (not to mention countless earlier threads); it might
resonably be described as an indirect constructor call.
But as I pointed out in the article you're replying to, but
misleadingly snipped by you, where instead you misleadingly
chose to discuss a different example, for the particular
example chosen by Jeff above, the standard, not surprisingly,
refers to the source code as a constructor call.
Where? The standard makes it perfectly clear that the above
will result in the definition of an object, whose lifetime
starts when control flow encounters the definition. The
standard also defines what it means for an object's lifetime to
start, and that includes calling the constructor. As far as I
can see, however, the standard refers to that bit of source code
as a definition, not as a constructor call.
We've been through this before. There is no syntax in the
standard which the standard calls a "constructor call" (unlike
the case for destructors). On can thus argue that at the source
code level, there is no such thing as "calling a constructor"
(and in certain contexts, it even makes sense to do so). The
standard does define what it means to call a constructor, and
under what circumstances the constructor will be called. And a
competent C++ programmer will certainly be aware which syntaxes
will result in the constructor being called (among other
things). If a programmer uses such a syntax, is he "calling the
constructor"? You seem to argue yes, but most other people I
know say no.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34