close
九、Miscellany
本章的第一個條款,強調不可輕忽 compiler warning messages。
第二個條款綜覽 C++ standard library,其中涵蓋由 TR1 引進的重大新機能。
第三個條款則綜覽 Boost,它是一個重要的 C++ 泛用型網站。

53、Pay attention to compiler warnings.
舉個例子,下列是多多少少會發生的錯誤:
class B {
  public:
    virtual void f() const;
};

class D : public B {
  public:
    virtual void f();
};

於是 compiler 可能會出現 warning message:
warning: D::f() hides virtual B::f()

這個 warning message 說明在 B 中的 f 並未在 D 中被重新宣告,而是整個被遮掩了,原因詳見條款 33
如果忽略這個 compiler warning,則可能導致錯誤的程式行為,然後是更多的除錯行為,只為了找出 compiler 早就偵測出來的事情。

warning message 跟 compiler 是相依的,不同的 compiler 有不同的標準。


努力在 compiler 的最嚴苛警告層級下爭取「無任何 warning message」。
不要過度依賴 compiler 的 warning 能力,不同的 compiler 對待事情的態度並不相同。




54、Familiarize yourself with the standard library, including TR1.
TR1 代表 "Technical Report 1",而 TR1 提供的機能幾乎對每一個程式庫和每一種應用都帶來利益。

C++98 列入的 C++ standard library 有:
      STL:包含 container, iterator, algorithm, function object, container adapter, function object adapter。
      iostream:包含使用者自定緩衝功能、國際化 I / O,及預先定義好的物件 cin, cout, cerr 及 clog。
      國際化支援:包括多區域能力。
      數值處理:包括複數模板和純數值陣列。
      exception hierarchy:包括 base class exception, derived class logic_error 和 runtime_error,及更深繼承的各個 class。
      C89 standard library。

TR1 詳細敘述了 14 個新 components,統統放在 std namespace 內,更正確的說是在其 nested namespace tr1 內:
std::tr1

組件實例:
  • smart pointer:tr1::shared_ptr 及 tr1::weak_ptr,詳見條款 13
  • tr1:function:此物的以表示任何 callable entity,只要其 signature 符合標的,詳見條款 35
  • tr1:bind:詳見條款 35

  • Hash table:
  • Regular Expression:
  • Tuples:
  • tr1::array:
  • tr1::mem_fn:
  • tr1:;reference_wrapper:
  • random number:
  • 數學特殊函數:
  • C99 相容擴充:

  • Type traits:
  • tr1::result_of:


C++ standard library 主要機能由 STL, iostream, locale 組成,並包含 C99 standard library。
TR1 添加了 smart pointer, 一般化 function pointer, hash-based container, regular expression 及另外 10 個 components 的支援。
TR1 本身只是一份規格,為了得到 TR1 提供的好處,還需要一份實物,一個好的實物來源是 Boost。




55、Familiarize yourself with Boost.
Boost 是一個 C++ 開發者集結的社群,也是一個可自由下載的 C++ 程式庫群,網址是 http://boost.org

Boost 的第一個特點:Boost 是由 C++ 標準委員會成員創設,因此 Boost 成員和委員會成員有很大的重疊。
第二:Boost 接納程式庫的過程是以 public peer review。

Boost 是一個社群,也是一個網站,致力於免費、源碼開放、同僚覆審的 C++ library development,Boost 在 C++ 標準化過程中扮演深具影響力的角色。
Boost 提供許多 TR1 組件實作品,以及其它許多函式庫。
arrow
arrow
    全站熱搜

    silverfoxkkk 發表在 痞客邦 留言(0) 人氣()