freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

c電子課件(下)第十章(參考版)

2024-10-19 15:50本頁面
  

【正文】 } 。 //打印 out_of_range error in ArrayelemType::operator[]() return 1。()39。 excp){ cerr39。 } coutendl。i++){ arr[i]=i+1。 try{ for(i=0。 [例 ] Array重新定義下標(biāo)操作符 [ ] int main(){ int i。 elemType * ia。} return ia[ix]。 operator[](int ix) const{ //下標(biāo)運(yùn)算符 [ ]重載 if(ix0||ix=size){ //增加異常拋出 ,防止索引值越界 string eObj=out_of_range error in Array elemType ::operator[]()。} ~ Array(){delete [] ia。 } catch子句輸出為: 棧滿,不能壓棧 棧已空,無法出棧 [例 ] Array重新定義下標(biāo)操作符 [ ] templatetypename elemTypeclass Array{ public: explicit Array(int sz=DefaultArraySize){ size=sz。 coutendl。i++) coutb[i]39。} //調(diào)用虛函數(shù) popOnEmpty::print() for(i=0。} catch(Excpamp。i9。eObj){()。 //到 a[8]時(shí)棧滿 ,異常 ()。i9。 Stack istack(8)。}}。}}。}}。}}。return 2。} catch(popOnEmptyint amp。 eObj){ ()。 return 0。\t39。i9。i++) b[i]=()。 for(i=0。i++) (a[i])。 for(i=0。 } [例 ]函數(shù) try塊( Function try Block) int main()try{ int a[9]={1,2,3,4,5,6,7,8,9}, b[9]={0},i。 coutendl。i++) coutb[i]39。} for(i=0。} catch(popOnEmptyintamp。i9。eObj){()。 //到 a[8]時(shí)棧滿 ,異常 ()。i9。 Stackintistack(8)。 //棧已空則不能退棧,拋出異常 return elements[top]。 //棧滿則拋出異常 elements[++top]=data。 [例 ] 堆棧異常處理 templatetypename T void StackT::Push(const T amp。} //判棧滿 void PrintStack()。} //清空棧 bool IsEmpty() const{return top== 1。 //彈出, top T GetElem(int i){return elements[i]。data) 。 //棧如不指定大小,設(shè)為 20元素 ~Stack(){delete[] elements。 //動(dòng)態(tài)建立的數(shù)值 int maxSize。 [例 ] 堆棧異常處理 templatetypename Tclass Stack{ int top。 templatetypename Tclass popOnEmpty{//??债惓B暶? public: void print(){cerr棧已空,無法出棧 endl。} void print(){cerr棧滿, value()未壓入棧 endl。 public: pushOnFull(T i){_value=i。 【 例 】 為類模板 Array重新定義下標(biāo)操作符 [],如果索引值越界,它會(huì)拋出一個(gè) out_of_range類型的異常。當(dāng) new()操作符不能分配所要求的存儲(chǔ)區(qū)時(shí),會(huì)拋出該異常。 以上三個(gè)異常是由 runtime_error類派生的 。 overflow_error異常,報(bào)告算術(shù)溢出錯(cuò)誤。 length_error異常,報(bào)告企圖產(chǎn)生“長度值超出最大允許值”的對象 domain_error異常,用以報(bào)告域錯(cuò)誤( domain error)。 } C++標(biāo)準(zhǔn)庫中的異常層次的根類被稱為 exception,定義在庫的頭文件 exception中 C++標(biāo)準(zhǔn)庫的異常類層次結(jié)構(gòu) (選讀 ) C++標(biāo)準(zhǔn)庫提供的邏輯異常: invalid_argument異常,接收到一個(gè)無效的實(shí)參,拋出該異常。 //析構(gòu)函數(shù) virtual const char* what() const throw() 。) throw() 。 //復(fù)制構(gòu)造函數(shù) exception amp。 //默認(rèn)構(gòu)造函數(shù) exception(const exception amp。因?yàn)楫?dāng)派生類的虛函數(shù)被指向基類類型的指針調(diào)用時(shí), 保證不會(huì)違背基類成員函數(shù)的異常規(guī)范 。 //對 ! 有相同的異常規(guī)范 string fun3() throw(string)。 class CDerived:public CBase{ public: int fun1(int) throw(int)。 virtual string fun3() throw(int,string)。 異常規(guī)范的引入: 異常規(guī)范(選讀) class CBase{ public: virtual int fun1(int) throw()。 T Pop() throw(popOnEmpty)。 異常規(guī)范( exception specification)提供了一種方案,可以隨著函數(shù)聲明列出該函數(shù)可能拋出的異常,并保證該函數(shù)不會(huì)拋出任何其他類型的異常,在 stack類定義中可有: void Push(const Tamp。 僅當(dāng)函數(shù)中所拋出的異常 , 沒有在該函數(shù)內(nèi)部處理 , 而是逆調(diào)用鏈回溯尋找匹配的 catch子句時(shí) , 異常規(guī)范才起作用 。 異常規(guī)范(選讀) 一個(gè)函數(shù)的異常規(guī)范的違例只能在運(yùn)行時(shí)才能被檢測出來 。 為了調(diào)用派生類對象的虛函數(shù),異常
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1