Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++, "canceling a construction"

Name: Anonymous 2009-11-04 15:25

Hi /prog/

My is simple, but perhaps not so frequent.

How should I stop a construction of an object (c++)?

Basically I have a class with some data members which must fulfill some requirements. Say we initialize these data members upon construction, if the supplied values were erroneous then I guess I want to stop construction and throw an error. Is this the right idea? How do I "cancel the construction"?

Help much appreciated :)

Name: Anonymous 2009-11-05 22:22

>>4
This might be considered splitting hairs, but the object is indeed "created" prior to invoking the constructor; as in, memory is set aside for the data members, they simply aren't set to anything meaningful prior to construction. I should point out that if you have allocated any memory in the constructor prior to the exception being thrown, you must make sure that that memory is reaped from inside the constructor.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List