搜索
熱搜: 活動 交友 discuz
查看: 1623|回復: 0
打印 上一主題 下一主題

[教學] effective C++ - 基礎篇

[複製鏈接]
跳轉到指定樓層
1#
發表於 2007-7-27 20:48:11 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
Item1:C++ 就像一個聯邦政府(主語言),統合許多州(子語言)
包含

1. C , 建立在 C 語言的基礎上
2. Object-Oriented, 類別(classes), 封裝(encapsulation),繼承( inheritance), 多型(polymorphism), 虛擬函數(virtual function)
3. Template C++, 泛型設計(generic programming)
4. STL, template library, 包含 container, iterators, algorithms, and function objects.

summary:C++ is a federation of 4 sublanguages, each with its own conventions.

- seperate line -

item2: prefer consts, enums and inlines to #defines

因為 #define 會由 preprocessor 先處理,compiler 永遠看不見,當發生 error 時有時很難追蹤出錯誤來源。

summary: 1. for simple constants, prefer const objects or enums to #defines.
              2. for function-like macros, prefer inline functions to #defines.

- seperate line -

item3: 盡可能用 const

用 const 可以幫助 compiler 偵測出使用上的錯誤

item4: 確保 objects 在使用之前已經初始化

manually initialize objects of built-in type, because C++ only sometimes initializes them itself.
in a constructor, prefer use the member initialization list to assignment inside the body of the constructor.
List data member in the initialization list in the same order they're declared in the class.
Avoid initialization order problems across translation units by replacing non-local static objects with local static objects.
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

本論壇為非營利之網路平台,所有文章內容均為網友自行發表,不代表論壇立場!若涉及侵權、違法等情事,請告知版主處理。


Page Rank Check

廣告刊登  |   交換連結  |   贊助我們  |   服務條款  |   免責聲明  |   客服中心  |   中央分站

手機版|中央論壇

GMT+8, 2024-5-18 20:42 , Processed in 0.017999 second(s), 16 queries .

Powered by Discuz!

© 2005-2015 Copyrights. Set by YIDAS

快速回復 返回頂部 返回列表