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

正文內(nèi)容

第六章類成員二(完整版)

  

【正文】 st成員函數(shù) 靜態(tài)成員變量與靜態(tài)成員函數(shù) 《面向?qū)ο蟪绦蛟O(shè)計(jì)》 中國(guó)科學(xué)技術(shù)大學(xué)計(jì)算機(jī)系 馬建輝 3 const量 (常量 ) 從高質(zhì)量程序設(shè)計(jì)的角度考察 C++中的 const! 《面向?qū)ο蟪绦蛟O(shè)計(jì)》 中國(guó)科學(xué)技術(shù)大學(xué)計(jì)算機(jī)系 馬建輝 4 const的意義 ?最低權(quán)限原則 : 軟件工程的基本原則之一 。 // 無(wú)需初始化 const int bufsize = 100 。(因此,不用擔(dān)心名字沖突) ? 當(dāng)定義一個(gè) const時(shí),必須賦一個(gè)值給它,除非用 extern做出了清楚的說(shuō)明。 struct S { int i, j。 int main() { cout type a character amp。 int const *v。d。 // illegal e const int* w = (int*)amp。 // But this works fine too! } ///:~ 對(duì)內(nèi)部類型來(lái)說(shuō),按值返回 const量并沒(méi)有什么特別的意義 。 } 《面向?qū)ο蟪绦蛟O(shè)計(jì)》 中國(guó)科學(xué)技術(shù)大學(xué)計(jì)算機(jī)系 馬建輝 16 X f5() { X x(2) return x。 //可能會(huì)有 Warning,跟編譯選項(xiàng)有關(guān) f6() = X(1)。 《面向?qū)ο蟪绦蛟O(shè)計(jì)》 中國(guó)科學(xué)技術(shù)大學(xué)計(jì)算機(jī)系 馬建輝 17 const的應(yīng)用: const指針 4. 傳遞和返回 const指針 char * strcpy(char * dest, const char * src); void t(int*) { } void u(const int* cip) { *cip = 2。x。 // Not OK const int* const ccip = w()。 void print()。 ? 問(wèn) : 如何獲得編譯期間整個(gè)類的恒定常量? ? 答 : 方法一: static const (見(jiàn)后續(xù)章節(jié) ) 方法二:枚舉常量 class A {… enum { SIZE1 = 100, SIZE2 = 200}。 //const對(duì)象 《面向?qū)ο蟪绦蛟O(shè)計(jì)》 中國(guó)科學(xué)技術(shù)大學(xué)計(jì)算機(jī)系 馬建輝 25 如何保證 const對(duì)象不被改變? ?公有數(shù)據(jù):只要用戶不去改變,這些數(shù)據(jù)保持不變是很容易實(shí)現(xiàn)的。 }。 // OK } 《面向?qū)ο蟪绦蛟O(shè)計(jì)》 中國(guó)科學(xué)技術(shù)大學(xué)計(jì)算機(jī)系 馬建輝 27 const對(duì)象與 const成員函數(shù) ? 聲明為 const的對(duì)象是不能被賦值的 ? 聲明為 const的對(duì)象不能隨便調(diào)用任意的成員函數(shù) ()。 10. srand(time(0))。 30. return quotes[lastquote = qnum]。 i++) 38. cout () endl。 ?const為程序設(shè)計(jì)提供了又一種非常好的類型檢查形式及安全性。 34. const Quoter cq。 14. } 15. const char* Quoter::quote() { 16. static const char* quotes[] = { 17. Are we having fun yet?, 18. Doctors always know best, 《面向?qū)ο蟪绦蛟O(shè)計(jì)》 中國(guó)科學(xué)技術(shù)大學(xué)計(jì)算機(jī)系 馬建輝 29 19. Is it ... Atomic?, 20. Fear is obscene, 21. There is no scientific evidence 22. to support the idea 23.
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1