Re: Constructor call
* Markus Moll:
Hi
cppquester@googlemail.com 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.
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.
but the creation of an unnamed
temporary. An object of type A is created, not at all used, and then
destroyed.
Yes.
Cheers, & hth.,
- Alf
Notes:
[1] <url:
http://www.google.com/search?q=stroustrup+koenig+%22explicit+constructor+call%22>
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?