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

正文內(nèi)容

靜態(tài)成員與友元ppt課件-在線瀏覽

2025-06-24 08:07本頁面
  

【正文】 udents=0。}。 //靜態(tài)數(shù)據(jù)成員在類外分配空間和 初始化 void fn() {Student s1。 cout Student::number() endl。 cout Student::number() endl。 Student類隨著對象的產(chǎn)生,每個對象都有一個 name成員值,但無論對象有多少,甚至沒有,靜態(tài)成員 noOfStudent也只有一個。 在 Student對象空間中,是沒有靜態(tài)數(shù)據(jù)成員 noOfStudents的,它的空間,不會隨著對象的產(chǎn)生而分配,或隨著對象的消失而收回。 靜態(tài)數(shù)據(jù)成員確實是在程序一開始運行時就必須存在。這樣,它的空間分配有三個可能的地方: ( 1)一是作為類的外部接口的頭文件,那里有類聲明; ( 2)二是類定義的內(nèi)部實現(xiàn),那里有類的成員函數(shù)定義; ( 3)三是應用程序的 main()函數(shù)前的全局數(shù)據(jù)聲明和定義處。類聲明只聲明一個類的 “ 尺寸與規(guī)格 ” ,并不進行實際的內(nèi)存分配,所以類聲明中寫成定義“ static int noOfStudents=0。它也不能在頭文件中類聲明的外部定義,因為那會造成在多個使用該類的源文件中,對其重復定義。 //student類的內(nèi)部實現(xiàn)部分 include “” //類的成員函數(shù)定義(沒有包括靜態(tài)數(shù)據(jù)成員定義) //應用程序重用了 student類 include “” include int Student::noOfStudents=0 //不便于重用 void fn() {Student s1。 cout“Student::number()endl。 coutStudent::number()endl。定義時,要用類名引導。 下面程序?qū)?: //**************************** //** ** //**************************** class Student {public: student (char * pName = ”no name”)。 static int number ()。 char name[40]。 //**************************** //** ** //**************************** include include include int Student :: noOfStudents =0。 strcpy (name, pName)。 //靜態(tài)成員:每創(chuàng)建一個對象 , 學生人數(shù)增 1 cout noOfStudents endl。 noOfStudents 。} int Student :: number() //靜態(tài)成員函數(shù) {return noOfStudents。 student s2。 } void main() {fn ()。} 工程文件 : 運行結(jié)果為: create one student 1 create one student 2 2 destruct one student 1 destruct one student 0 0 返回 公共靜態(tài)數(shù)據(jù)成員可
點擊復制文檔內(nèi)容
教學課件相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1