C++ styles

来源:互联网 发布:北京博彦网鼎java面试 编辑:程序博客网 时间:2024/06/09 23:35

1. An entity (function, class, etc) only has one compact responsibility.

    design small class, and seperate incompact functions.

 

2. Use 'const' as more as possible.

    for example:

          

 

3. Always initialize variables.

   For example:

        

4. derivation  is  'is-a'  relation, which means 'words-like-a'

 

5. hide overloading functions.

    For example

        

   The method foo(int, int) and foo() are hidden after derivation.  The solution is to add one sentence 'using A::foo' into B (just remove the comment tag in above example ) .

 

原创粉丝点击