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

正文內(nèi)容

第四章類型檢查-文庫(kù)吧

2025-08-25 12:28 本頁(yè)面


【正文】 型的基類型是程序設(shè)計(jì)語(yǔ)言提供的,而子類的基類是程序設(shè)計(jì)者自己定義的。 Ada語(yǔ)言的源程序中可以定義整型數(shù)的子類型和派生類型height和 weight如下: subtype height is integer range 1..200。 身高 subtype weight is integer range 1..200。 體重 type height is range 1..200。 身高 type weight is range 1..200。 體重 integer上的所有運(yùn)算均適用于 height和 weight , 但是它們的值集合均是 integer的子集 [1, 200]。 派生類型被認(rèn)為是新的類型,并且不在同一類型中的變量不能一起運(yùn)算。 ② 特定多態(tài):有限個(gè)不同的、且不關(guān)聯(lián)的類型 b. 強(qiáng)制( coercion): 強(qiáng)制是根據(jù)應(yīng)用需求對(duì)類型進(jìn)行內(nèi)部轉(zhuǎn)換,以減少重載的類型。 例如: 表達(dá)式 3+ + 3+ + +可以是: 1. 4種重載類型,對(duì)應(yīng)四種形式的運(yùn)算; 2. 1種重載類型,所有形式的運(yùn)算均強(qiáng)制為 real+real; 3. 兩種重載類型: int+int和 real+real。 int+real和 real+int均強(qiáng)制為 real+real。 a. 重載( overload): 相同的操作符施加于不同的操作對(duì)象,根據(jù)上下文確定操作的具體類型,即采用哪段代碼序列實(shí)現(xiàn)此操作。 例如: 表達(dá)式 x+y中的 +可以是數(shù)的加、字符串的聯(lián)接和集合的并。 3 幾乎多態(tài)的語(yǔ)言 多態(tài)既保持了強(qiáng)類型,又增加了程序設(shè)計(jì)語(yǔ)言的靈活性和功能。但是,傳統(tǒng)的程序設(shè)計(jì)語(yǔ)言如 Pascal、 Ada8 C等,并不是真正的多態(tài)語(yǔ)言,因?yàn)樗鼈儍H支持部分的多態(tài),即將多態(tài)看作為 exception而不是 rule。 面向?qū)ο蟪绦蛟O(shè)計(jì)語(yǔ)言( OOPL) ObjectOriented = data abstractions + object types + type inheritance 1. 從類型發(fā)展的觀點(diǎn)看, OOPL應(yīng)該是強(qiáng)類型的、多態(tài)的、且對(duì)象類型化的。 2. 它與過(guò)程式程序設(shè)計(jì)語(yǔ)言的最大區(qū)別在于, OOPL引入了類與類的繼承。 OOPL是程序設(shè)計(jì)語(yǔ)言的一個(gè)重要發(fā)展,它的最重要特征之一就是將對(duì)象類型化,即將構(gòu)造新的類型的權(quán)利交給了程序設(shè)計(jì)語(yǔ)言的使用者。 換句話說(shuō),傳統(tǒng)的 PL為我們提供了 類型 (僅提供了簡(jiǎn)單類型),而 OOPL為我們提供了構(gòu)造(定義)類型的 方法 。 1 Ada83支持 data abstractions 1. 基于對(duì)象的程序設(shè)計(jì)語(yǔ)言,源程序重要組成: package; 2. package組成:規(guī)格說(shuō)明 (specification)與體 (body)。 package stack is 規(guī)格說(shuō)明 procedure push(x : in object)。 procedure pop(x : out object)。 ...... end stack。 package body stack is 體 procedure push(x:in object) is ...... end push。 ...... end stack。 使用: with stack。 use stack。 ... push(x)。 或者 with stack。 ... (x)。 2 Ada83程序包不是類型 Ada的記錄 類型 : const max_students = 200。 學(xué)生人數(shù)最大值 const max_teachers = 20。 教師人數(shù)最大值 type name_str is array (1..10) of character。 姓名 type student_type is record 學(xué)生記錄 id_no : student_id_no。 name : name_str。 end record。 type teacher_type is record 教師記錄 id_no : teacher_id_no。 name : name_str。 end record。 type class is record 班級(jí)記錄 students : array (1..max_students) of student_type。 teachers : array (1..max_teachers) of teacher_type。 end record。 2 Ada83程序包不是類型(續(xù)) 問(wèn)題: 是否可以象聲明記錄類型的變量那樣聲明 package的實(shí)例? 但是不可以為 package聲明對(duì)象,例如: stack1,stack2:stack。 ?? (x)。 ?? 因?yàn)?package不是類型! 可以為記錄類型聲明對(duì)象并使用它們,例如 : C0014, S00 : class。 [i].name:= 張三 。 [j].name:= 李四 。 3 面向?qū)ο髾C(jī)制的兩種實(shí)現(xiàn)方法 過(guò)程式程序設(shè)計(jì)語(yǔ)言實(shí)現(xiàn)類型化與繼承機(jī)制的兩條途徑: 1. 記錄類型中擴(kuò)充操作 2. 擴(kuò)充抽象數(shù)據(jù)類型( ADT或程序包)為類型 1. ADT類型化- Ada95 的標(biāo)簽類型 a. 類的定義 package class_account is private end class_account。 b. 對(duì)象的聲明與引用 Mike : account。 deposit(Mike, )。 type account is tagged private。 subtype Money is float。 procedure deposit(the:in out account。 amount:in Money)。 function balance(the:in account) return Money。 type account is tagged record balance_of : Money := 。 end record。 1. ADT類型化(續(xù) 1) with class_account。 use class_account。 package class_interest_account is private end class_interest_account。 d. 繼承機(jī)制下對(duì)象的聲明與引用 corinna : interest_account。 deposit(corinna, )。 calc_interest(corinna)。 type interest_account is new account with private。 procedure calc_interest(the:in out interest_account)。 ... type interest_account is new account with record accumulated_interest : Money := 。 end record。 ... c. 類的繼承(派生類) 2. C++結(jié)構(gòu)的擴(kuò)充 C++通過(guò)對(duì) C的 struct進(jìn)行擴(kuò)
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1