Topic: Nit of the day.
Author: rfg@lupine.ncd.com (Ron Guilmette)
Date: 14 Dec 90 02:33:21 GMT Raw View
I'm at it again. Picking nits as usual.
Given:
struct S {
int i;
};
void S (void);
void foobar ()
{
S ();
}
Did I call the explicitly declared function `S' or did I call the
implicitly compiler-created constructor for `struct S'?
References to E&S would be appreciated.
Author: lijewski@batcomputer.tn.cornell.edu (Mike Lijewski)
Date: 16 Dec 90 20:04:41 GMT Raw View
In article <3000@lupine.NCD.COM> rfg@lupine.ncd.com (Ron Guilmette) writes:
>I'm at it again. Picking nits as usual.
>
>Given:
>
> struct S {
> int i;
> };
>
> void S (void);
>
> void foobar ()
> {
> S ();
> }
>
>Did I call the explicitly declared function `S' or did I call the
>implicitly compiler-created constructor for `struct S'?
Good question. On page 27 of E&S is an example very similar to yours.
The answer in that case is the function `S' would be called. If we
then turn to page 167 there is an example of a class X with an explicit
constructor w/ prototype X(int);. If we also have a function void X(int);
the statement X(1); becomes ambiguous. Seems to me we need a much better
explanation of when an implicitely-defined default constructor is
generated and, a bit more explicitely, can I call such a constructor
in a program. I would also like to know why a default
constructor is generated for EVERY class which has no explicitely-
declared constructors (page 264 E&S). Seems to me this contradicts the
example on page 27.
--
Mike Lijewski (H)607/272-0238 (W)607/254-8686
Cornell National Supercomputer Facility
ARPA: lijewski@theory.tn.cornell.edu BITNET: mjlx@cornellf.bitnet
SMAIL: 25 Renwick Heights Road, Ithaca, NY 14850