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

正文內(nèi)容

c講義完整版ppt課件-資料下載頁

2025-05-12 04:19本頁面
  

【正文】 void Down()。 void Zero()。 void Value()。 private: int a。 }。 課堂練習(xí) 設(shè)計(jì)一個(gè)棧類型,考慮下面的數(shù)據(jù)結(jié)構(gòu) const int STACK_SIZE=20。 class CStack{ public: CStack()。 CStack(int sz)。 ~CStack()。 void push(int e)。 int pop()。 private: int *item。 int sp。 int size。 }。 課堂練習(xí) private: int *item。 int sp。 int size。 }。 CPoint類 聲明一個(gè) CPoint類來描述點(diǎn)對(duì)象。 // class CPoint{ public: CPoint (int x, int y)。 int XCoord()。 int YCoord()。 void Move(int xOffset, int yOffset)。 private: int X,Y。 }。 CPoint:: TPoint(int x,int y) { X=x。 Y=y。 } int CPoint:: XCoord() {return X。} int CPoint:: YCoord() {return Y。 } void CPoint:: Move(int xOffset, int yOffset) { X+= xOffset。 Y+=yOffset。 } void main(void) { CPoint p(3,4)。 (10,20)。 cout‘(‘()‘,‘ ()‘)‘endl。 } 類的靜態(tài)成員 ? 在 C語言中有靜態(tài)變量的概念 ? 局部靜態(tài)變量 ,相當(dāng)于一個(gè)局部范圍內(nèi)能夠使用的全局變量 ? 對(duì)應(yīng)地,在 C++中也有靜態(tài)成員的概念 ? 靜態(tài)數(shù)據(jù)成員 ? 靜態(tài)成員函數(shù) 靜態(tài)數(shù)據(jù)成員 ? 用關(guān)鍵字 static聲明 ? 該類的所有對(duì)象維護(hù)該成員的同一個(gè)拷貝 Class Score { char student[20]。 int language。 int maths。 int history。 Public: static int passmark。 static int passnum。 Score()。 ~Score()。 }。 靜態(tài)數(shù)據(jù)成員 ? 必須在類外定義和初始化,用 (::)來指明所屬的類 int Score::passmark = 60。 Int Score::passnum = 0。 ? 上述定義和初始化必須放在 main()函數(shù)的外面來進(jìn)行,象全局變量一樣 int Score::passmark = 60。 Int Score::passnum = 0。 void main() { …. } Void main() { int Score::passmark = 60。 int Score::passnum = 0。 …… } Static int Score::passmark = 60。 Static int Score::passnum = 0。 void main() { …. } 靜態(tài)數(shù)據(jù)成員 ? 靜態(tài)數(shù)據(jù)成員在類中僅僅是說明 ? 其內(nèi)存空間是在初始化語句時(shí)進(jìn)行分配的 ? 在類中說明靜態(tài)數(shù)據(jù)成員是不能進(jìn)行初始化 Class Score { char student[20]。 int language。 int maths。 int history。 Public: static int passmark = 60。 static int passnum = 0。 Score()。 ~Score()。 }。 靜態(tài)數(shù)據(jù)成員 ? 靜態(tài)數(shù)據(jù)成員可以是公有的,也可以是私有的或保護(hù)的 ? 公有靜態(tài)數(shù)據(jù)成員可以在類外訪問 ? 象普通成員函數(shù)一樣通過對(duì)象來訪問 void main() { cout Score::passmark endl。 …. } void main() { Score s。 cout endl。 } 沒有任何理由推薦這種調(diào)用方式,因?yàn)殪o態(tài)數(shù)據(jù)成員是獨(dú)立于類對(duì)象的 靜態(tài)數(shù)據(jù)成員 ? 如果在類的成員函數(shù)中訪問靜態(tài)數(shù)據(jù)成員時(shí)可以將類名和分辨符省略 Class Score { char student[20]。 int language。 int maths。 int history。 Public: static int passmark。 static int passnum。 Score() { Score::passmark=60。 passnum=0。 ~Score()。 }。 靜態(tài)數(shù)據(jù)成員 ? 例子:給予上面的類說明 include int Score::passmark = 50。 int Score::passnum = 0。 void main() { cout Score::passmark endl。 // 輸出是多少? Score s。 cout endl。 // 輸出又是多少? cout Score::passmark endl。 // 輸出又是多少? } 靜態(tài)數(shù)據(jù)成員 ? 私有靜態(tài)數(shù)據(jù)成員 ? 象公有靜態(tài)成員一樣進(jìn)行定義和初始化 ? 在類外不能進(jìn)行訪問,只有類的成員函數(shù)才能訪問它 ? 保護(hù)型靜態(tài)數(shù)據(jù)成員 ? 象公有靜態(tài)數(shù)據(jù)成員一樣定義和初始化 ? 在類中可以訪問它 ? 在類的子類中也可能可以訪問它 在后面類的繼承中講述 靜態(tài)成員函數(shù) ? 一個(gè)成員函數(shù)可以是靜態(tài)的 class Student { char filename[20]。 int age。 int grade。 static int total。 public: void PrintInfo()。 static void PrintTotal()。 }。 靜態(tài)成員函數(shù) 靜態(tài)成員函數(shù) ? 與靜態(tài)數(shù)據(jù)成員類似,靜態(tài)成員函數(shù)不依賴于類的對(duì)象而存在 ? 類外代碼可以使用類名和作用域操作符來調(diào)用靜態(tài)成員函數(shù)。 ? class_name::func_name(arguments_list)。 ? Student::PrintTotal()。 ? 靜態(tài)成員函數(shù)也可以象普通成員函數(shù)那樣調(diào)用 ? Student s。 ? ()。 沒有任何理由推薦這種調(diào)用方式,因?yàn)殪o態(tài)成員函數(shù)是獨(dú)立于類對(duì)象的 靜態(tài)成員函數(shù) ? 在類的成員函數(shù)中調(diào)用靜態(tài)成員函數(shù)時(shí),其類名和分別符可以省略 ? Student::PrintTotal()。 // 推薦方式 ? PrintTotal()。 // 非推薦方式 ? 靜態(tài)成員函數(shù)也有三種類型 ? 公有靜態(tài)成員函數(shù) ? 私有靜態(tài)成員函數(shù) ? 保護(hù)型靜態(tài)成員函數(shù) ? 公有靜態(tài)成員函數(shù)可以在類外進(jìn)行調(diào)用 ? 私有靜態(tài)成員函數(shù)可以在類內(nèi)進(jìn)行調(diào)用 ? 保護(hù)型靜態(tài)成員函數(shù)可以在類內(nèi)或其子類中調(diào)用 靜態(tài)成員函數(shù) ? 類的靜態(tài)成員函數(shù)不能試圖直接訪問普通數(shù)據(jù)成員和調(diào)用普通成員函數(shù) class A { public: static void f1()。 private: int x。 }。 void A::f1() { cout x endl。 //錯(cuò)誤 A a。 cout endl。 // 正確 } 為什么? 靜態(tài)對(duì)象 ? 局部靜態(tài)對(duì)象與 C中的靜態(tài)局部變量非常類似,但需要注意構(gòu)造函數(shù)和析構(gòu)函數(shù)的調(diào)用 ? 其構(gòu)造函數(shù)在代碼執(zhí)行過程中,第一次遇到它的變量定義時(shí)被調(diào)用,當(dāng)函數(shù)再次進(jìn)入時(shí)就不再再次調(diào)用構(gòu)造函數(shù) ? 其析構(gòu)函數(shù)在整個(gè)程序執(zhí)行結(jié)束后,進(jìn)程退出前被調(diào)用 靜態(tài)對(duì)象 ? 全局靜態(tài)對(duì)象 (變量 )與全局對(duì)象 (變量 )等價(jià) ? 全局靜態(tài)對(duì)象與 C中的全局靜態(tài)變量也非常類似,但也需要注意構(gòu)造函數(shù)和析構(gòu)函數(shù)的調(diào)用 ? 其構(gòu)造函數(shù)在 main()函數(shù)前被調(diào)用,如果有多個(gè)全局對(duì)象,構(gòu)造函數(shù)調(diào)用順序取決于變量的定義順序 ? 其析構(gòu)函數(shù)在整個(gè)程序執(zhí)行結(jié)束后,進(jìn)程退出前被調(diào)用 練習(xí) 記錄一個(gè)類在程序運(yùn)行時(shí)有多少個(gè)對(duì)象被創(chuàng)建。 class TPoint{ public: TPoint(int x,int y)。 int XCoord()。 int YCoord()。 ~ TPoint()。 static int ObjectExisted()。 private: static int Number。 int X,Y。 }。 友元 ? 通常,對(duì)于類的私有成員,外部類或外部函數(shù)是無法訪問和調(diào)用它們的 ? 但有的時(shí)候某些類或函數(shù)需要訪問另外一些類的私有成員 ? 通過友元可以實(shí)現(xiàn)這種訪問控制 ? 友元函數(shù) ? 友元類 ? 需要注意的是,友元打破了數(shù)據(jù)封裝和數(shù)據(jù)隱藏的概念。但這種開放在某些時(shí)候是非常必要的,尤其是對(duì)于操作符的重載 友元函數(shù) ? 友元函數(shù)是在類定義中由關(guān)鍵字 friend修飾說明的非成員函數(shù),在它的函數(shù)體中能夠通過對(duì)象名訪問 private 和 protected成員 ? 訪問對(duì)象中的成員必須通過對(duì)象名 友元函數(shù) include include class Point { public: Point(double xi, double yi) {X=xi。 Y=yi。 } double GetX() {return X。} double GetY() {return Y。} friend double Distance( Pointamp。 a, Pointamp。 b)。 private: double X, Y。 }。 友元函數(shù) double Distance( Pointamp。 a, Pointamp。 b) { double dx=。 double dy=。 return sqrt(dx*dx+dy*dy)。 } int main() { Point p1(, ), p2(, )。 double d=Distance(p1, p2)。 coutThe distance is dendl。 return 0。 } 友元函數(shù) ? 友元函數(shù)的說明可以放在類中的任何位置,public部分、 private部分、或 protected部分 ? 它們具有相同的含義,因?yàn)橛言瘮?shù)不是類的成員函數(shù) ? 所以,一般將友元函數(shù)說明放在 public部分 友元類 ? 若類 A為類 B的友元類,則類 A的所有成員函數(shù)都能訪問類 B的私有成員 (私有成員數(shù)據(jù)和私有成員函數(shù) )。 ? 定義語法:將友元類名在另一個(gè)類中使用friend修飾說明。 友元類 class A { friend class B。 public: void Display() {coutxendl。} private: int x。 } class B { public: void Set(int i)。 void Display()。 private: A a。 }。 友元類 void B::Set(int i) { =i。 } void B::Display() { ()。 } 友元類 ? 與友元函數(shù)類似,友元類的的說明可以放在類中的任何位置, public部分、 private部分、或 protected部分 ? 它們具有相同的含義 ? 所以,一般將友元函數(shù)說明放在 public部分 重載 重載指的是一個(gè)標(biāo)識(shí)符或運(yùn)算符可同
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1