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

正文內(nèi)容

[工學(xué)]面向?qū)ο蟪绦蛟O(shè)計語言c第05章運算符重載-閱讀頁

2024-10-28 22:20本頁面
  

【正文】 Complex amp。 if(0) os+iendl。 return os。 operator(istream amp。 c) { is。 } void main( ) { Complex obj1,obj2。 coutobj1“ ”obj2。 動態(tài)存儲區(qū)的分配和釋放一定要 成對 出現(xiàn) 。 int size。 cp=new Complex[size]。 造成指針懸掛原因是對指向 new申請的存儲空間的指針變量進行賦值修改 。 p=new char[10]。 strcpy(p, abcd)。 delete [] p。 //錯誤 , 同樣的空間被釋放兩次 44 ? 對象的拷貝有兩種方式: 初始化和賦值 。 對象的指針成員直接賦值,就可能導(dǎo)致指針懸掛。int sz。 } ~String ( ) {delete [ ] pstr。 void main( ) { String str1(10)。 String str3(10)。 } 執(zhí)行該程序,會出現(xiàn)問題。 str) { pstr =。 } 修改為 String::String(const String amp。 strcpy(pstr,)。 str) { pstr =。 } 修改為 String String ::operator=(const String amp。 strcpy(pstr1,)。 pstr=pstr1。 } 集合的實現(xiàn) ? C++中沒有集合類型,可以定義一個集合類來實現(xiàn)。 int size。 public: Set(int a)。 void expend(int offset)。 int In(int )。 Set operator +(Set )。 friend void operator(ostream amp。 Set(const Set amp。 Set operator=(const Set amp。 void clear( )。 Set Set::operator*(Set t){ Set temp(size)。ahave。 return temp。 int a。ahave。 for (a=0。a++) if (In([a])==1) ([a])。 } Set::Set (const Set amp。 have=。 numhave。 } Set Set::operator=(const Set amp。t) { delete[ ] p。 have=。 nhave。 } //end of if return *this。 對于類類型 , 是否也存在一種類型轉(zhuǎn)換機制 , 使得類對象之間能進行類型轉(zhuǎn)換 ? 一般 , 類對象的類型轉(zhuǎn)換可由 構(gòu)造函數(shù) 和 轉(zhuǎn)換函數(shù) 實現(xiàn) 。 在 C++中 , 類被視為用戶定義的類型 , 可以像系統(tǒng)預(yù)定義類型一樣進行類型轉(zhuǎn)換 。 具有標(biāo)準(zhǔn)類型參數(shù)的構(gòu)造函數(shù)說明了一種從參數(shù)類型到該類類型的轉(zhuǎn)換 。 public: INTEGER (int i)。 }。 } INTEGER::INTEGER(const char *str) { num=strlen(str)。 obj1=20。 obj2==Du 。*/ } 第五章 引論 ? 類型轉(zhuǎn)換運算符的重載 類類型轉(zhuǎn)換函數(shù) 帶一個參數(shù)的構(gòu)造函數(shù)可以進行類型轉(zhuǎn)換 , 但是它的轉(zhuǎn)換功能很受限制 。 62 第五章 引論 ? 類型轉(zhuǎn)換運算符的重載 類類型轉(zhuǎn)換函數(shù) C++允許程序員為類定義一個類型轉(zhuǎn)換函數(shù) , 它的語法是 Class_Name::operator type( ) { … return (type類型的實例 )。 63 第五章 引論 ? 類型轉(zhuǎn)換運算符的重載 類類型轉(zhuǎn)換函數(shù) class INTEGER { int num。 } operator int( ) { return num。 64 void main( ) { INTEGER obj(12)。 anint=(int)obj。 // int( ) } ? 實現(xiàn)一個 Point類 ( 數(shù)據(jù)成員為一個點在兩維直角坐標(biāo)系內(nèi)的坐標(biāo) ) ; 實現(xiàn)一個 Vector類 ( 數(shù)據(jù)成員為一個點在兩維極坐標(biāo)系內(nèi)的坐標(biāo) ) ; 要求兩個類的對象能互相賦值 。 class Vector。 int x。 public: Point(int initx=0,int inity=0) {x=initx。} operator Vector( )。 operator (ostream amp。 return s。 class Vector{ friend Point 。 double seta。seta=initseta。 friend ostream amp。 s,Vector obj) {s‘,’‘\n’。} }。 =p*cos(seta)。 return Pobj。 =sqrt(x*x+y*y)。 else if (y0 ) =3*PI/2。 } else =atan(y/x)。
點擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1