国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
關(guān)于構(gòu)造函數(shù)中的異常處理
作  者:tt_xtj ()
等  級(jí):
信 譽(yù) 值: 100
所屬論壇: C/C++ C++ 語言
問題點(diǎn)數(shù): 20
回復(fù)次數(shù): 13
發(fā)表時(shí)間: 2006-10-12 13:17:05
在c++中,如果對(duì)象的構(gòu)造函數(shù)有異常被拋出,則該對(duì)象不會(huì)被構(gòu)造,對(duì)嗎?所
那么,構(gòu)造該對(duì)象所分配的空間由誰負(fù)責(zé)釋放(如果該對(duì)象是由new在堆中分配的呢)?
例如如下代碼:
#include <iostream>
#include <string>
using namespace std;
class test
{
public:
test(int m):n(m)
{
cout<<"Input:\n";
cin>>s;
if (s=="exception")
{
cout<<this<<endl<<sizeof(*this)<<endl;
cout<<&n<<endl;
throw s;
}
}
virtual ~test()
{
}
private:
int n;
string s;
int t;
};
void main()
{
test*ptrT;
try
{
ptrT=new test(6);
}
catch (string s)
{
cout<<s<<endl;
}
//delete ptrT;
test t2(8);
}
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
C++析構(gòu)函數(shù)詳解
C++函數(shù)返回值為對(duì)象時(shí),構(gòu)造析構(gòu)函數(shù)的執(zhí)行細(xì)節(jié)
C 類(深拷貝和淺拷貝)
return *this
調(diào)用有參構(gòu)造函數(shù)的三種方法
C++拷貝構(gòu)造函數(shù)詳解(轉(zhuǎn))
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服