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

正文內(nèi)容

第六章類成員(二)-全文預(yù)覽

2024-09-29 08:31 上一頁面

下一頁面
  

【正文】 2. int lastquote。 ()。 } int X::f(){ … 。 int const_f() const。 ?對象如何知道哪些成員函數(shù)將會(huì)改變數(shù)據(jù)? ?對象如何知道哪些成員函數(shù)對于 const對象來說是安全的? ?解決方法: 強(qiáng)制聲明和定義 const成員函數(shù),顯式地告訴編譯器這些函數(shù)對數(shù)據(jù)是安全的,可以被 const對象調(diào)用。 const int i=1。 int array2[SIZE2]。 2. 這些 const成員相互獨(dú)立,可以有不同的值。 Fred::Fred(int sz) : size(sz) {} void Fred::print() { cout size endl。 《面向?qū)ο蟪绦蛟O(shè)計(jì)》 中國科學(xué)技術(shù)大學(xué)計(jì)算機(jī)系 馬建輝 20 作業(yè): (上機(jī) ) (上機(jī) ) 《面向?qū)ο蟪绦蛟O(shè)計(jì)》 中國科學(xué)技術(shù)大學(xué)計(jì)算機(jī)系 馬建輝 21 const對象與 const成員函數(shù) 本節(jié)討論 const在類中的應(yīng)用 ?const數(shù)據(jù)成員 ?const成員函數(shù) ?const對象 《面向?qū)ο蟪绦蛟O(shè)計(jì)》 中國科學(xué)技術(shù)大學(xué)計(jì)算機(jī)系 馬建輝 22 const數(shù)據(jù)成員 class Fred { const int size。 // OK //! *w() = 1。 // OK u(cip)。x。 // 返回靜態(tài)局部量的地址 } 《面向?qū)ο蟪绦蛟O(shè)計(jì)》 中國科學(xué)技術(shù)大學(xué)計(jì)算機(jī)系 馬建輝 18 int main() { int x = 0。 // OK copies value int* ip2 = cip。class X amp。 // Error: f6()是常量,不能被修改 f7(f6())。 // 正確, f5()返回非 const量; f5().modify()。 // 按值返回 const。 X::X(int ii) { i = ii。 class X { int i。 int main() { const int j = f3()。 // legal but bad practice int main() {} ///:~ ? 注意 《面向?qū)ο蟪绦蛟O(shè)計(jì)》 中國科學(xué)技術(shù)大學(xué)計(jì)算機(jī)系 馬建輝 13 const的應(yīng)用: const參數(shù) 1. 傳遞 const值 void f1(const int i) { i++。 // OK d not const //! int* v = amp。 (因?yàn)檫@樣做可能導(dǎo)致通過非 const指針改變 const對象的值的后果 ) int d = 1。d。 int * const w = amp。 } ///:~ 《面向?qū)ο蟪绦蛟O(shè)計(jì)》 中國科學(xué)技術(shù)大學(xué)計(jì)算機(jī)系 馬建輝 10 const的應(yīng)用: const指針 1. 指向 const的指針 (指針指向的內(nèi)存地址的值不能改變 ) const int *u。 const char c = ()。 ? 在宏替換中, BUFSIZE沒有類型信息,不能進(jìn)行類型檢查; ? 宏定義是全局的,容易名字沖突。 const S s[] = { { 1, 2 }, { 3, 4 } }。 float f[i[3]]。 extern const int bufsize。 char strbuf[bufsize]。 // error!! Why?? 在編譯時(shí),編譯器并不知道 const的值,它只是一個(gè)“ 運(yùn)行時(shí)常量 ” 。也就是說,默認(rèn)情況下, const是外部連接的 (容易引起 “ 名字沖突 ” )。 eg: const in
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1