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

正文內(nèi)容

靜態(tài)成員與友元ppt課件-展示頁

2025-05-16 08:07本頁面
  

【正文】 class Student { public: Student(char* pName =no name) {cout create one student\n。 成員有數(shù)據(jù)成員和成員函數(shù)之分,靜態(tài)成員也有靜態(tài)數(shù)據(jù)成員和靜態(tài)成員函數(shù)之分。這就是靜態(tài)成員的作用。 返回 一個類的屬性是該類所有對象的屬性,而不是這個類某個對象的屬性。} 運行結(jié)果: Assigning student id 1 Constructing student Randy Destructing id 1 全局變量 nextStudentId, 它既不能放在頭文件中定義,也不能放在類 StudentId的內(nèi)部實現(xiàn)中,只能放在應(yīng)用程序中主函數(shù) main()的前面。}。} protected:char name[20]。 strcpy(name,pName)。}。 cout“Destructing id”valueendl。 cout“Assigning student id ”valueendl。 靜態(tài)成員的需要性 靜態(tài)成員的使用 靜態(tài)數(shù)據(jù)成員 靜態(tài)成員函數(shù) 需要友元的原因 友元的使用 include include int nextStudentID=0。 聲明為 static的類成員便能在類范圍中共享,稱之為靜態(tài)成員。第 15章 靜態(tài)成員與友元 類是類型而不是對象,每個類的對象都是該類數(shù)據(jù)成員的拷貝。 然而,往往需要讓類的所有對象在類的范圍內(nèi)共享某個數(shù)據(jù)。 友元函數(shù)完全是普通的 C++函數(shù),不同的是,它可以訪問類的保護成員或私有成員,方便編程,提高了效率,但卻破壞了類的封裝。 Class StudentID {public:StudentID( ) {value=++nextStudentID。} ~StudentID( ) { nextStudentID。} protected:int value。 Class Student {public:Student(char *pName=“noName”) {cout“Constructing student”pNameendl。 name[sizeof(name)1]=?\0?。 StudentID id。 Void main( ) {Student s(“Randy”)。 在重用 StudentId類的時候,總是還要額外的考慮一個全局變量的處置,這不得不使類的封裝性受到傷害。因此,我們需要一種能標是類的屬性而不是單個對象屬性的方法。 一個類的靜態(tài)數(shù)據(jù)成員是用來表示類的屬性的成員,而不是對象的屬性的成員。 靜態(tài)成員用 static聲明。 strncpy(name, pName,40)。\039。 //靜態(tài)成員:每創(chuàng)建一個對象,學生人數(shù)增 1 cout noOfStudents endl。 noOfStudents。} static int number() //靜態(tài)成員函數(shù) {return noOfStudents。 //若寫成 noOfSt
點擊復(fù)制文檔內(nèi)容
教學課件相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1