Topic: 5.2.3 Explicit type conversion (functional
Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/06/03 Raw View
mrice@quip.eecs.umich.edu (Michael Rice) writes:
>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.
>>No. Class "A" has a (trivial) default constructor generated by the compiler.
>>That ctor does nothing. If you add a ctor requiring parameters to A,
>>it will then not have a default ctor, and the line of code in question
>>will no longer be valid. Of course, you can define a default ctor
>>which sets the memory used by A::x to zero if you wish.
>That's certainly how compilers currently operate.
>So exactly when can the otherwise section of 5.2.3 paragraph 2 happen? That
>is, when can a class not have a default constructor (trivial or not)?
There is a special case for C-like structs ("POD-structs"). A POD-
struct object of static storage duration is zero-initialized, the same
as in C. I don't have the original example that started this
thread, but I seem to remember that it was a static POD-struct -- no C++
features. In that case, it should be zero-initialized.
--
Steve Clamage, stephen.clamage@eng.sun.com
Author: freyburg@glitch.stanford.edu (Brian Michael Freyburger)
Date: 1995/06/03 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.
> >No. Class "A" has a (trivial) default constructor generated by the compiler.
> >That ctor does nothing. If you add a ctor requiring parameters to A,
> >it will then not have a default ctor, and the line of code in question
> >will no longer be valid. Of course, you can define a default ctor
> >which sets the memory used by A::x to zero if you wish.
> >
> That's certainly how compilers currently operate.
> So exactly when can the otherwise section of 5.2.3 paragraph 2 happen? That
> is, when can a class not have a default constructor (trivial or not)?
int foo()
{
int i = int();
return i;
}
Author: rac@intrigue.com (Robert Coie)
Date: 1995/06/03 Raw View
In article <3qnrhu$rtf@zip.eecs.umich.edu>, mrice@quip.eecs.umich.edu
(Michael Rice) wrote:
: 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.
[snip]
: So exactly when can the otherwise section of 5.2.3 paragraph 2 happen? That
: is, when can a class not have a default constructor (trivial or not)?
I thought the otherwise part referred to built-in types.
Robert Coie rac@intrigue.com
Implementor, Intrigue Corporation AppleLink: INTRIGUE
Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/06/02 Raw View
In article lbp@zip.eecs.umich.edu, mrice@quip.eecs.umich.edu (Michael Rice) writes:
>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:
>
> ...
>struct A {
> int x[10];
>};
>
>main()
>{
> A avar = A();
> ...
>}
>
>As I understand this the array inside A should be filled with zeros.
No. Class "A" has a (trivial) default constructor generated by the compiler.
That ctor does nothing. If you add a ctor requiring parameters to A,
it will then not have a default ctor, and the line of code in question
will no longer be valid. Of course, you can define a default ctor
which sets the memory used by A::x to zero if you wish.
---
Steve Clamage, stephen.clamage@eng.sun.com
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.
>No. Class "A" has a (trivial) default constructor generated by the compiler.
>That ctor does nothing. If you add a ctor requiring parameters to A,
>it will then not have a default ctor, and the line of code in question
>will no longer be valid. Of course, you can define a default ctor
>which sets the memory used by A::x to zero if you wish.
>
That's certainly how compilers currently operate.
So exactly when can the otherwise section of 5.2.3 paragraph 2 happen? That
is, when can a class not have a default constructor (trivial or not)?