[xsd-users] default contructor issue

Rizzuto, Raymond Raymond.Rizzuto at sig.com
Thu Jun 26 14:02:46 EDT 2008


Boris,

Thanks - I will take off that option so I and the other users are forced
to properly initialize the mandatory items.

Initially, I thought a default constructor plus setting values
explicitly was clearer to read.  The need to chain constructors, as
shown below, botherers me a bit:

    NewRequest::RequestType request(DomainObject::IdType("request-1",
"SusexToSDMP", 3),
                                     Request::StateType::Discarded,
                                     Request::ReceivedDateTimeType(2008,
1, 22, 8, 0, 0, 0, 0));

Of course, I can always construct my DomainObject::IdType before hand
and pass the object on the NewRequest::RequestType constructor call.

Thanks again for clarifying this point.

Ray

-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com]
Sent: Thursday, June 26, 2008 1:30 PM
To: Rizzuto, Raymond
Cc: xsd-users at codesynthesis.com
Subject: Re: [xsd-users] default contructor issue

Hi Ray,

Rizzuto, Raymond <Raymond.Rizzuto at sig.com> writes:

> I had been using the default constructor (via -generate-default-ctor),
> and forgot to initializing a DateTime mandatory element.  When I went
> to serialize the object, I got an access violation.  Is that a bug?
> Should I have instead gotten an xml_schema::Exception?

No this is not a bug. By default the generated code makes sure that you
initialize all required attributes and elements by forcing you to
initialize them at construction. By specifying --generate-default-ctor
you choose to take the risk of forgetting to initialize some required
members. This is clearly specifying in this option's documentation.
Adding extra checks in the serialization code (as well as in accessors
for consistency) will penalize people who use the strict interface by
hurting performance and increasing object code size.

Boris

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.




More information about the xsd-users mailing list