简体   繁体   English

新构造函数引发异常后的对象指针状态 - C ++

[英]Object Pointer Status After New Constructor Throws Exception - C++

What is going to be the status of an object pointer when a new class constructor throws an exception in C++? 当新的类构造函数在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? 当这个代码执行pobjMyClass的值时,抛出异常后会是什么? A pointer to an invalid instance of CMyClass , 0xA5A5A5A5 , NULL , some random uninitialized value, or something else? 指向CMyClass的无效实例, 0xA5A5A5A5NULL ,某些随机未初始化值或其他内容的指针? Thanks. 谢谢。

由于在赋值发生之前抛出异常,pobjMyClass将是以前的任何东西 - 在你的情况下,0xa5a5a5a5。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM