C++自修入門實境秀、C++ Primer 5版研讀秀 12/ ~第2章圓滿





0:22 2.6.3. Writing Our Own Header Files 撰寫我們自己的標頭檔

library type 程式庫型別

標頭檔通常儲存的是類別的定義或const、constexpr的變數

標頭檔常須用到其他標頭檔的資源(機能 facilities),也就是說標頭檔常須互相參照

23:12

Because a header might be included more than once, we need to write our headers in a way that is safe even if the header is included multiple times.

因為一個標頭不能被引入超過一次,我們必須以引入多次也安全的方式來撰寫我們的標頭。

原文無「不」,翻錯了。

source file

header file

27:05

A Brief Introduction to the Preprocessor

前置處理器的簡介

預處理式的簡介

source 原始碼

頁77 34:00

原來 #include即是預處理式(前置處理器 preprocessor)處理的對象

38:50 44:30

header guard標頭守衛

要寫自己的標頭檔時要注意前置標頭守衛(header guard)

前置處理器變數(preprocessor variable)

51:20

要定義一個預處理式變數要用 #define 這個directive(指示詞)

另有二個指示器也可以用來判斷預處理式(前置處理器 reprocessor)的變數是否為未定義(not defined)54:44



#ifdef(if defined)

#ifndef(if not defined)

……

#endif 58:00 1:0:50

可見 if ~~到 ~~ endif 是一對的,如VB的語法

59:30

to guard against multiple inclusion

避免多重引入



1:6:15預處理式(前置處理器 preprocessor)碰到前置處理器(preprocessor)變數只執行一次



as follows 如下

1:44:00

The preprocessor will process the lines following #ifndef up to the #endif . As a result, the preprocessor variable SALES_DATA_H will be defined and the contents of Sales_data.h will be copied into our program.

前置處理器會處理接在#ifndef 之前到#endif為止的程式行。結果就是,前置處理器變數SALES_DATA_H將會被定義,而 Sales_data.h的內容會被拷貝到我們的程式中。

「之前」是「之後」之誤。

標頭守衛(header guard)1:13:20 1:48:15習慣上都是以大寫字母寫成以避免與應用程式的其他部分的識別項(indetifier)衝突。

1:14:50 翻譯學 1:25:30「無時無刻、無日無夜」說解

1:14:50 1:39:48

Best Practices 養成好習慣

Headers should have guards, even if they aren’t (yet) included by another header. Header guards are trivial to write, and by habitually defining them you don’t need to decide whether they are needed.

即使沒有引入任何其他的標頭,標頭也應該擁有守衛。標頭守衛寫起來很簡單,只要習慣性地定義它們,你就不需要去判斷它們是否必要。1:49:45

「即使沒有引入任何其他的標頭」據原文應翻作「即使沒有被其他標頭引入」。

只要養成習慣在標頭檔都寫上標頭守衛(header guard),就不用怕在引入#include標頭會有任何引入問題出現

1:54:03

練習2.42

頁78 2:2:10 2:6:20

representation表示法



compound type A type that is defined in terms of another type.

A compound type is one that is defined in terms of another type.

複合型別是以其他型別來定義的一種型別。2:10:10 2:17:20翻譯學

2:18:20 in terms of 就=以……來=而=以中文能力……

複合型別(compound type)2:17:20是就其他型別來定義的一種型別。所以複合型別(compound type)2:24:40並不是指把兩個型別湊在一塊的意思。正是因為它是「another type」來定義的,所以叫作「compound」即:

配制 compound, make up

篹 compile, compose, compound, indite 2:13:30 2:26:47馬丁·海德格《林中路》

翻成「借義型別」或「藉型型別」還比較好

2:31:17

abstractions 抽象層

2:31:38

address Number by which a byte in memory can be found.

address (位址)一個號碼,記憶體中的每個位元組都可以透過這種號碼被找到。

Number:一組數字 2:37:55

arithmetic type算術型別



array Data structure that holds a collection of unnamed objects that are accessed by an index. Section 3.5 covers arrays in detail.

陣列是一種資料結構

covers:討論、說明(詳明)2:40:00



type specifier: 2:40:15 auto、base type、decltype 3:10:10



auto 是一個型別指示符型別指定符(type specifier),它會藉由一個變數的初始器初始設定式(initializer)來估算/推定該變數的型別



2:43:40 base type



The base type provides the common type on which the declarators in a declaration can build.

這句中文版漏翻了!2:46:14

基礎型別哲人提供了一種通用的型別,這種型別是一個宣告裡宣告單元宣告器declarators可以能夠、會、將建置起來的型別。



2:50:00 bind繫結

2:55:35

type qualifier:const

2:57:22

const reference Colloquial synonym for reference to const .

對常值型別的參考,也就是參考的本尊是常值(型別)。2:58:33

3:3:09 data member

頁79 3:11:31

default initialization How objects are initialized when no explicit initializer is given. How class type objects are initialized is controlled by the class. Objects of built-in type defined at global scope are initialized to 0; those defined at local scope are uninitialized and have undefined values.

類別型別的物件(執行個體)如何被初始化是由該類別來定義規定的 3:14:40

those ⑧找對主詞 是代「Objects of built-in type」 3:17:30

globeal scope 公領域(全域範疇)

local scope 私領域(區域範疇)

3:22:20 definition定義

3:23:59escape sequence Alternative mechanism for representing characters, particularly for those without printable representations. An escape sequence is a backslash followed by a character, three or fewer octal digits, or an x followed by a hexadecimal number.

轉義序列(escape sequence)3:30:30



header guard Preprocessor variable used to prevent a header from being included more than once in a single file.3:32:05

可見標頭守衛(header guard)就是前置處理器(preprocessor)變數嘛

標頭守衛(header guard)的作用就是保護或保證一個標頭檔不會被另一個檔案引入2次以上。每個檔案引入標頭檔都只能是1次!

3:34:50

identifier識別項(識別字)



3:40:37

list initialization Form of initialization that uses curly braces to enclose one or more initializers.

串列初始化(list initialization)

一個初始化是用用大括號將初始器括起來的表示法,就是串列初始化。



3:47:40 字面值(literal)不能被改變

3:50:22

character 字符(字母+符號)

字面值的字符character是用單引號括起來的

字面值的字串string,是用雙引號括起來的

3:55:24

低層const是型別整體的一部分,不可分割的



member Part of a class.

可見成員就是類別的部分、組成

3:59:40nonprintable character

4:1:49

object A region of memory that has a type. A variable is an object that has a name.

可見object和veriable的區別就在於有沒有名稱。變數是有名稱名字的物件(東西、對象)。4:3:52

可以說「變數」就是「具名物件或參考」(named object→veriable)

5:6:10

variable A named object or reference. In C++, variables must be declared before they are used.



pointer An object that can hold the address of an object, the address one past the end of an object, or zero.4:7:47

指針(指標)就是一個物件,和參考不同,參考不是物件。

而且指針只會記錄對於其他物件位址的訊息。

這裡表示指針可以儲存的資訊有3種:4:8:52

1.對某個物件位址的儲存

2.記錄了通過(超出)一個物件結尾位置的位址

3.零或空的指針



A pointer to const may not be used to change the value of the object to which it points.4:11:00

對const的指標不能被用來變更它所指的物件的值。

「所」即有「的」的功能了,所以「的」可以省略。

對const的指標不能被用來變更它所指物件的值。4:13:33

這就是中文程度對「所」不夠明白才會造成的翻譯。∴ 中文能力重不重要?!

4:20:13

reference An alias for another object.

可見參考簡捷的定義就是某個物件的「別名」。



reference to const A reference that may not change the value of the object to which it refers.A reference to const may be bound to a const object,a non const object,or the result of an expression.4:28:30

reference to const (對 const 的指標)不能改變其所指涉(refers)的物件之值的參考。對const的參考可以繫結至一個const物件、一 個非const物件,或一個運算式的結果。

指標 → 參考。4:24:44 4:28:33

頁80 4:29:38

scope The portion of a program in which names have meaning. C++ has several levels of scope:

global —names defined outside any other scope

class —names defined inside a class namespace —names defined inside a namespace

block —names defined inside a block

Scopes nest. Once a name is declared, it is accessible until the end of the scope in which it was declared.4:31:50 4:33:00

Scopes nest. ⑦先抓動詞 nest ⑧找對主詞 Scopes

4:41:50

signed Integer type that holds negative or positive values, including zero.

可見有號、無號是和integer型別有關。這個sign(符號)其實就是減號/負號(minus)!

4:45:00

temporary Unnamed object created by the compiler while evaluating an expression. A temporary exists until the end of the largest expression that encloses the expression for which it was created.

Unnamed object,不具名的物件。

4:49:07

type alias A name that is a synonym for another type. Defined through either a typedef or an alias declaration.4:51:10

型別別名的定義可以有兩種方式:一個是用typedef 來定義;一個是用別名宣告式來定義。別名宣告式就是 using X= type

4:55:30

type checking Term used to describe the process by which the compiler verifies that the way objects of a given type are used is consistent with the definition of that type.4:56:00

「Term used to describe」這句中文版沒翻出來

一個術語,用來表示

type specifier The name of a type.

原來一個型別的名稱就是所謂的「型別指定符」



5:8:00 void*

5:9:14

word The natural unit of integer computation on a given machine. Usually a word is large enough to hold an address. On a 32-bit machine a word is typically 4 bytes.

word (字組)給定機器上,整數計算的自然單位。通常一個字組的大小都足以存放一個位址。 在32位元的機器上,一個字組的大小通常會是 4個位元組。

給定機器上→在某台機器上

a given在中文往往翻成「某個」就可以了,不用翻出「給(定)」這樣的字義,就好像 in term of這個片語一樣,難道還要翻出term詞彙這個字義嗎?「term」在這裡翻成「講、說」還比較適當;就像「given」這裡翻成「某個存在的」才比較適當

留言

熱門文章