Topic: 5.2.3 Explicit type conversion (functional notation)
Author: mrice@quip.eecs.umich.edu (Michael Rice)
Date: 1995/06/02 Raw View
Section 5.2.3 of the draft paragraph 2:
A simple-type-specifier followed by a (empty) pair of parentheses constructs
a value of the specified type. If the type is a class with a default
constructor, that constructor will be called; otherwise the result is the
default value given to a static object of the specified type.
Take this program as an example:
#include <iostream.h>
struct A {
int x[10];
};
main()
{
A avar = A();
for(int i=0; i < 10; ++i)
cout << avar.x[i] << " ";
cout << endl;
return 0;
}
As I understand this the array inside A should be filled with zeros.
I don't think this is how existing compilers work. So how will this be
accomplished? As I see it, either a) a real static object of type A is
created (which is guaranteed to be all zero) and copied to avar; or b)
the compiler has to generate a "everything to zero" copy constructor.
Both don't seem too implementor friendly.
Seems to me, if the programmer wanted his members initialized to ANYTHING
he would supply a constructor or initialize each instance. What is the
rationale for this?
Comments?