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.
由于在赋值发生之前抛出异常,pobjMyClass将是以前的任何东西 - 在你的情况下,0xa5a5a5a5。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.