close

原文:
http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Declaration_Order

在一個class中,規定declaration的順序為public → protected → private。這樣的規定通常是為了程式的可讀性,把越重要的部份擺在越前面,一個class的interface(廣義的interface)就是它與外界溝通的那些public member functions,所以將public section放在最前面,而只有該class內部會用到的data member或help functions自然就設為private並且放在最後面。

而在每一個section當中,Google C++ Style Guide規定宣告的順序為:
1. Typedefs and Enums
2. Constants (static const data members)
3. Constructors
4. Destructor
5. Methods, including static methods
6. Data Members (except static const data members)

而friend declaration和Google C++ Style Guide自定義的DISALLOW_COPY_AND_ASSIGN macro應放在private section的最後面。

而與header file相對應的.cpp file中放置了該class的definition。在這個.cpp file中,其definition的順序應與declaration的順序一樣。而將definition放置在header file的那些member funcitons是implicit inline;切記只有短小且常用的functions才適合inline。

arrow
arrow
    文章標籤
    C++
    全站熱搜

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