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

正文內(nèi)容

第六章類(lèi)成員(二)(文件)

 

【正文】 《面向?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。 return amp。x。 // OK //! t(cip)。 // Not OK const int* const ccip = w()。 《面向?qū)ο蟪绦蛟O(shè)計(jì)》 中國(guó)科學(xué)技術(shù)大學(xué)計(jì)算機(jī)系 馬建輝 19 ?對(duì)參數(shù)傳遞而言, C++建議用 const引用傳遞替代值傳遞。 void print()。 (), (), ()。 ? 問(wèn) : 如何獲得編譯期間整個(gè)類(lèi)的恒定常量? ? 答 : 方法一: static const (見(jiàn)后續(xù)章節(jié) ) 方法二:枚舉常量 class A {… enum { SIZE1 = 100, SIZE2 = 200}。 ?注意: 枚舉常量并不是類(lèi)成員,也不會(huì)占用對(duì)象的存儲(chǔ)空間,它們?cè)诰幾g時(shí)被全部求值。 //const對(duì)象 《面向?qū)ο蟪绦蛟O(shè)計(jì)》 中國(guó)科學(xué)技術(shù)大學(xué)計(jì)算機(jī)系 馬建輝 25 如何保證 const對(duì)象不被改變? ?公有數(shù)據(jù):只要用戶(hù)不去改變,這些數(shù)據(jù)保持不變是很容易實(shí)現(xiàn)的。 class X { int i。 }。 int main() { X x1(10)。 // OK } 《面向?qū)ο蟪绦蛟O(shè)計(jì)》 中國(guó)科學(xué)技術(shù)大學(xué)計(jì)算機(jī)系 馬建輝 27 const對(duì)象與 const成員函數(shù) ? 聲明為 const的對(duì)象是不能被賦值的 ? 聲明為 const的對(duì)象不能隨便調(diào)用任意的成員函數(shù) ()。 5. int lastQuote() const。 10. srand(time(0))。 27. int qnum = rand() % qsize。 30. return quotes[lastquote = qnum]。 // OK 36. //! ()。 i++) 38. cout () endl。 《面向?qū)ο蟪绦蛟O(shè)計(jì)》 中國(guó)科學(xué)技術(shù)大學(xué)計(jì)算機(jī)系 馬建輝 31 作業(yè): P366(中文版 P196): (上機(jī) ) (提示:參考 167。 ?const為程序設(shè)計(jì)提供了又一種非常好的類(lèi)型檢查形式及安全性。 non const function 37. for(int i = 0。 34. const Quoter cq。amp。 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. that life is serious, 24. Things that make us happy, make us wise, 25. }。 7. }。 //OK ?const的成員函數(shù)不能改變成員變量 《面向?qū)ο蟪绦蛟O(shè)計(jì)》 中國(guó)科學(xué)技術(shù)大學(xué)計(jì)算機(jī)系 馬建輝 28 例 :const成員函數(shù)與非 const成員函數(shù) 1. class Quoter {
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1