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

正文內(nèi)容

類(lèi)和對(duì)象ppt課件(參考版)

2025-05-06 03:07本頁(yè)面
  

【正文】 s3=(s2)。 return *this。 對(duì)象本身加一個(gè)數(shù): Sample Sample ::add(const Sample amp。} Sample add( Sample s1,Sample s2)。} Sample(int m){ n=m。 } include class Sample { private: int n。 //s4=(s1,s2)。 ()。 } void main() { Sample s1(10),s2(5),s3。 ?this指針大量用于 運(yùn)算符重載 成員函數(shù) —— 第八章 Sample Sample:: add(Sample s1,Sample s2) { thisn=+。 } 注意: ?this指針 只能 在類(lèi)的成員函數(shù)中使用 ? 它指向該成員函數(shù)被調(diào)用時(shí)的對(duì)象 ?靜態(tài)成員函數(shù) 沒(méi)有 this指針 ?因?yàn)轭?lèi)只有一個(gè)靜態(tài)成員函數(shù)實(shí)例,使用 this指針沒(méi)有什么意義,在靜態(tài)成員函數(shù)中使用 this指針會(huì)引起編譯錯(cuò)誤。 //實(shí)際是 Sample::addvalue(5 , amp。 void main() { Sample s(10)。 } [例 ] ?類(lèi)每個(gè) 成員函數(shù) 都有一個(gè) 隱含 的 常量 指針參數(shù) ,——稱(chēng)為 this指針 . ? this指針的 類(lèi)型 —— 類(lèi)的類(lèi)型 ?調(diào)用成員函數(shù)時(shí) ,this指針被初始化為 當(dāng)前對(duì)象的地址 . void Sample::addvalue(int n) { thisn+=n。 //修改書(shū)上 P111! } void main() { Sample s(10)。 }。 void disp(){ cout‖n=‖nendl。 類(lèi)成員函數(shù)指針 ?同一個(gè)函數(shù)如何處理不同的對(duì)象的數(shù)據(jù)? this指針 include class Sample { public: Sample() { } Sample(int n){ thisn=n。n=20 ?注意 :程序中類(lèi) Sample的 setm和 setn成員函數(shù)必須具有相同的返回類(lèi)型 (這里均為 void),而且僅當(dāng)為 public時(shí)才能這樣使用,為什么,請(qǐng)大家思考。 ()。 pfun=Sample::setn。 pfun=Sample::setm。 void main() { void (Sample::*pfun)(int)。 } private: int m,n。 } void setn(int i) {n=i。 注意 ?指向類(lèi)成員函數(shù)指針的定義: 類(lèi)型 (類(lèi)型 ::*指針名 ) (參數(shù)表 ) ?給類(lèi)成員函數(shù)指針賦值的格式如下 : 指向函數(shù)的指針名 =函數(shù)名 ? 程序中使用指向指針調(diào)用函數(shù)的格式如下 : (*指向函數(shù)的指針名 )(參數(shù)表 ) 類(lèi)成員函數(shù)指針 [例 ] include int s=0。 } 運(yùn)行結(jié)果: m=10 n=20 ?:程序中類(lèi) Sample的 m和 n數(shù)據(jù)成員必須具有相同的數(shù)據(jù)類(lèi)型(這里均為 int),而且僅當(dāng)為 public時(shí)才能這樣使用。 //=20。Sample::n。 //=10。 Sample a。 void main() { int Sample::*p = amp。 int m,n。 cout‖n=‖nendl。 [例 6. 14類(lèi)數(shù)據(jù)成員指針 ] include int s=0。 class Sample { public: int m,n。 p=amp。 p=amp。n。 int *p。 ?包括類(lèi) 數(shù)據(jù)成員指針 和 類(lèi)成員函數(shù)指針 。} c tPoint::getcountP()。 cout()。 Point p2(3,4)。 int Point::countP=0。} int getcountP(){return countP。} int getx() { return x。p) { x=。 countP++。 public: Point(int x1=0,int y1=0) { x=x1。 } 運(yùn)行結(jié)果 s=5 include class Point { private: int x,y。 Sample::add()。 int Sample::n=0。 } static void add() { s+=n。 class Sample { private: static int n。但靜態(tài)數(shù)據(jù)成員和靜態(tài)成員函數(shù)可由任意訪(fǎng)問(wèn)權(quán)限許可的函數(shù)訪(fǎng)問(wèn)。 靜態(tài)成員函數(shù) ?靜態(tài)成員函數(shù)只能訪(fǎng)問(wèn) 該類(lèi)的靜態(tài)數(shù)據(jù)成員、靜態(tài)成員函數(shù) 和 類(lèi)以外的函數(shù)和數(shù)據(jù) ,不能訪(fǎng)問(wèn) 類(lèi)中的 非靜態(tài)數(shù)據(jù)成員 (因?yàn)榉庆o態(tài)數(shù)據(jù)成員只有對(duì)象存在時(shí)才有意義) 。 } 例:所創(chuàng)建的 Point對(duì)象的個(gè)數(shù) 結(jié)果: 2 2 ?只想用類(lèi)的成員函數(shù)卻不想創(chuàng)建對(duì)象,行不? ?只想得到點(diǎn)的個(gè)數(shù) (靜態(tài)成員變量 ),不想使用具體的對(duì)象,可以不? ?只要類(lèi)存在,不用定義對(duì)象,就可以使用靜態(tài)成員函數(shù) ?定義 static 類(lèi)型 靜態(tài)成員名 (函數(shù)表 )。 cout()endl。 void main(){ Point p1(1,2)。} }。} int gety() { return y。 y=。 } Point(const Point amp。 y=y1。 static int countP。 cout‖s=‖Sample::sendl。 cout‖s=‖Sample::sendl。 void main() { Sample a(2),b(5),c(8)。 }。 } void add() { s+=n。 靜態(tài)數(shù)據(jù)成員 [例 ] include class Sample { int n。 (不能在構(gòu)造函數(shù)中初始化?。? ?靜態(tài)數(shù)據(jù)成員不屬于任何一個(gè)對(duì)象,所以必須初始化! 類(lèi)型 類(lèi)名 ::靜態(tài)數(shù)據(jù)成員 =值 。 int countP。 //調(diào)用 void print() ()。 ()。 //常對(duì)象樣品為 0號(hào) Cloth b(2022003,175)。 } }。 } void print() {cout ID=IDendl。 //服裝尺寸 ——普通數(shù)據(jù)成員 public: Cloth(int id,int s) { ID=id。 //對(duì)!調(diào)用 void print() const常對(duì)象能調(diào)用常成員函數(shù) ID=2022003 ID=2022000 象一般數(shù)據(jù)一樣 ,類(lèi)的數(shù)據(jù)成員也可以是常量 ?問(wèn)題: ?一個(gè)對(duì)象從創(chuàng)建開(kāi)始存在期間都不變的一些數(shù)據(jù)? 如 ID? ?常數(shù)據(jù)成員 ?使用 const說(shuō)明的數(shù)據(jù)成員 . ?常數(shù)據(jù)成員的 初始化 ?構(gòu)造函數(shù) 只能 通過(guò) 初始化列表 對(duì)類(lèi)中的 常數(shù)據(jù)成員 進(jìn)行初始化 .程序代碼中構(gòu)造函數(shù) Sample 的格式如下 : Sample(int id):n(id) { } class Cloth{ private: const int ID。 錯(cuò)!常對(duì)象不能調(diào)用一般的成員函數(shù) } 例:常成員函數(shù) 修改 Cloth類(lèi) 參考 例 void print() const {cout ID=IDendl。 ()。 //常對(duì)象樣品為 0號(hào) Cloth b(20220003,175)。 } }。 } v
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1