What is going to be the status of an object pointer when a new class constructor throws an exception in C++? Take the following code for example:
CMyClass * pobjMyClass = (CMyClass *)0xA5A5A5A5;
try
{
pobjMyClass = new CMyClass(); // Exception thrown in constructor
}
catch ( ... ) {}
When this code executes what will the value of pobjMyClass
be, after the exception is thrown? A pointer to an invalid instance of CMyClass
, 0xA5A5A5A5
, NULL
, some random uninitialized value, or something else? Thanks.
Since the exception is thrown before the assignment takes place, pobjMyClass will be whatever it was before - in your case, 0xa5a5a5a5.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With