---
# System prepended metadata

title: OOP 讀書會 - 0x0001 課堂筆記
tags: [OOP 讀書會]

---

# OOP 讀書會 - 0x0001 課堂筆記

###### tags: `OOP 讀書會`

[toc]

Introduction
===

- [課程大綱](https://moodle.ntust.edu.tw/pluginfile.php/774101/mod_resource/content/1/LecturePlanning-CandCPP-%2010902.pdf)

授課老師
---

- 戴文凱
- 主持 [NTUST game lab](https://www.youtube.com/channel/UCIrPge2oPNlvb4yh1ze-jwQ)

Basis
===

Components in old C
---

- Directives
    eg.
    ```c++
    #include <...>
    using namespace ...;
    ```

- Funtions
    > 程式碼的五臟六腑
    
    eg.
    ```c++
    int hello(int arg){
        ...
    }
    ```
    
- Statement
    eg.
    ```c++
    i = 5;
    ```

Why better than C?
---

> C++ 把程式提升到**哲學**的層次

I/O
---

- cin
    - 讀取的流程
        1. 設定 pointer 為 0
        2. 讀取第一組字
            1. 如果是 white space，不存，繼續讀
            2. 否則存起來，繼續讀直到遇到 white space
    - 讀到 white space 之後會回傳前面的東西，然後退一位，也就是說：下一個讀到的字元會是 white space

Function Basis
===

Definition
---

- UML
    - Activity diagram
    - Flow chart

- funtion head
    ```cpp
    double func(int arg)
    ```
- function body
    ```cpp
    return arg + 1;
    ```
- funtion definition
    ```cpp
    double func(int arg){
        return arg + 1;
    }
    ```

Pre defined funtions
---

- 系統幫妳寫好的
    - 或是 communities 寫的
- 哪裡找?
    - ~~The Home Depot~~
    - reference
        - [C++ standard library](https://en.cppreference.com/w/cpp/header)
    - open source code
    - mate's code

Vector
===

- vector 是個 template，要經過 `<type>` **特化**
- **CRUD**
    - 新增 (Create)、讀取 (Read/Retrive)、修改 (Update)、刪除 (Delete)
- 在初始化時，vector 會預先跟系統要固定量的記憶體（可用 capacity 取得量值）。當用盡時，再跟系統要一些。此行為稱為 **batch**。

Call-by-reference
===

- 傳統的 call-by-value，是把 **值** 傳入 function，在 function 內做的任何更動不會影響

Developing flow
===

- Top down
    - 先寫好 `driver`，`stubs` 先 return 一個暫時的值，待 `stub` 完成 & submit 後馬上就可以看到（可使用的）結果。
    
Array
===

Memory
---

- 觀念上，array 在記憶體內的空間一定是連續的。
- 但實際上不一定，取決於 OS memory management。
- 刪除多維 array 的時候要一層一層刪，不可以只刪頭。

Vector
---

- An array-alike class, with enhancements

Structure
===

- 多個不同型別的集合
- 可以用 `type name: space;` 指定該欄位(field)的 **位元 (bit)** 數
- 可以用 `=` 複製。
- member 預設是 public

Class
===

- Structure + 行為(member funtions)
- 資料封裝
    - 可以確保資料不會被影響
    - 沒加 `public:` 的都是 private，不可以在 class 外部存取
- Q: inline, macro, 和一般的 funtion 差在哪？

operator overload
---

自定義 `+`、`-`、`*`、`/`、`=`

### `const` function

> ```=cpp
> int func(int arg) const;
> ```

- **表示**不會改變 class 內的資料
- constant object 只能 call constant funtion
- 只是防呆

Class Design Workshop
===









