关于指向new的指针的疑问
假设有个Weight类(私有成员为指向Bitmap类的指针p)
定义赋值构造函数如下
Weight& Weight::operator=(const Weight& x)
{
if(this==&x)return *this;
delete p;
p=new Bitmap(*x.p);
return *this;
}
假设有个Weight类(私有成员为指向Bitmap类的指针p)
定义赋值构造函数如下
Weight& Weight::operator=(const Weight& x)
{
if(this==&x)return *this;
delete p;
p=new Bitmap(*x.p);
return *this;
}
想问如果new Bitmap导致异常(如分配内存不足),那指针p会指向哪里?
int * pout;
try
{
C o1;
int * p = new int;
*p = 0;
o1.f();
pout = p;
}
catch(std::bad_alloc)
{
pout = nullptr;
}
int * pout;
-->;
byte mem_o1[sizeof(C)];
((mem_o1 *))->C();
p = new int;
*p=0;
((mem_o1 *))->f();
pout = p;
((mem_o1 *))->~C();
--<;
int * pout;
-->;
byte mem_o1[sizeof(C)];
((mem_o1 *))->C();
new int;
__EXCP -->
((mem_o1 *))->~C();
pout = nullptr;
__EXCP --<
--<;