* Markus Moll:
(e-mail address removed) wrote:
What does this code do?
#include <iostream>
class A
{
public:
A() { std::cout << "A::A()" << std::endl;}
};
int main( int argc, char* argv[])
{
A(); // constructor call?
return 0;
}
I.e.
a) What does this constructor call do?
It's not really a constructor call,
Depends on whose terminology you adopt.
In the terminology used in the standard, and by the language's
creator Bjarne Stroustrup[1] and people like Andrew Koenig and
Nicolai Josuttis, it's an explicit constructor call.
According to the standard, it's a "Explicit type conversion
(functional notation)". The semantics of this expression are
specified to be "creates an rvalue of the specified type, which
is value-initialized".
Of course, informally, I'll call it a constructor call too (and
formally, I find it awkward to speak of an explicit type
conversion when there's nothing being converted). But for
whatever reasons, that's not the language the standard uses in
its formal definition of the construction.
It is however a popular sport among some contributors to
clc++, which group has even included some competent folks, to
deny that that can make sense. Happily the numbers have
dwindled. I'm using the authority argument above because
that's the only one that's worked with them.
The authority argument is IMHO the only one which can be made to
work against what you are saying
. Calling it an explicit
type conversion doesn't make any sense. But that's what the
standard does.
The only explination I can think of as to why the standard uses
such strange terminology is that 1) it doesn't want to talk
about constructors for things like int (and of course, "int()"
is another example of this type of expression), or 2) it doesn't
want to treat the case with a single argument (i.e. "A(b)") as a
special case (and of course, that case may call a user defined
conversion operator on b, rather than the constructor of A).
Of course, it is more than *just* a constructor call---the
compiler also allocates memory for the object.