1、數(shù)據(jù)與函數(shù)是構(gòu)成類(lèi)的基礎(chǔ)
2、declaration:頭文件的防衛(wèi)式申明
? ? ? ? #ifndef
? ? ? ?#define
? ? ? ?0-前置申明
? ? ? ?1-類(lèi)申明
? ? ? ?2-類(lèi)定義
? ? ? ?#endif
3、構(gòu)造函數(shù)
? ? ? A、構(gòu)造函數(shù)名稱(chēng)與class一致
? ? ? B、有參數(shù),有默認(rèn)實(shí)參
? ? ? C、不需要返回類(lèi)型
? ? ? D、盡量使用初始列
4、參數(shù)傳遞和返回值傳遞有兩種:by value和by reference,優(yōu)先考慮by reference
5、friend:可自由取得private里的數(shù)據(jù)
6、typename()——?jiǎng)?chuàng)建臨時(shí)對(duì)象,臨時(shí)對(duì)象不可by reference
7、類(lèi)的實(shí)現(xiàn)
? ? ? A、防衛(wèi)式申明
? ? ? B、類(lèi)定義
? ? ? ? ? ? a、類(lèi)需要哪些數(shù)據(jù),放private,考慮數(shù)據(jù)的類(lèi)型
? ? ? ? ? ? b、函數(shù)放public
? ? ? ? ? ? c、所有類(lèi)先想構(gòu)造函數(shù)——構(gòu)造函數(shù)需要哪些參數(shù),要不要默認(rèn)值,參數(shù)傳refrence還是value,初始列
? ? ? ? ? ? d、考慮構(gòu)造函數(shù)還需要做什么
8、設(shè)計(jì)函數(shù)時(shí)需要考慮:函數(shù)要不要加const,參數(shù)是什么,傳refrence還是value,參數(shù)要不要const,函數(shù)返回值傳refrence還是value
9、全局函數(shù)變成員函數(shù)加inline