12.10

Google C++ Style Guide

 

1. Doing Work in Constructors

  Avoid virtual method calls in constructors, and avoid initialization that can fail if you can't signal an error.

2. Implicit Conversions

  Do not define implicit conversions. Use explicit keyword for conversion operators and single-argument constructors.

3. Copyable and Movable Types

  A class's public API should make explicit whether the class is copable, move-only, or neither copyable not movable. Support copying and/or moving if these operations are clear and meaningful for your type.

4. Structs vs. Classes

  Use a struct for passive objects that carry data; everything else is a class.

  What is traits in C++?

5. Inheritance

  Composition is often more appropriate than inheritance. When using inheritance, make it public.

  What is virtual dispatch?

  What is "Diamond" inheritance patterns?

  What is the keyword 'final' for?

6. Operator Overloading

  Overload operators judiciously. Do not create user-defined literals.

7. Access Control

  Make classes' data members private, unless they are static const.

8. Declaration Order

  Group similar declarations together, placing public parts earlier.

9. Output Parameters

  Prefer using return values rather than output parameters. If output-only parameters are used they should appear after input parameters.

10. Write Short Functions

  Prefer small and focused functions.

11. Reference Arguments

  All parameters passed by lvalue reference must be labeled const.

12. Function Overloading

  Use overloaded functions only if a reader looking at a call site can get a good idea of what is happening without having to first figure out exactly which overload is being called.

 

转载于:https://www.cnblogs.com/lefthook/p/10099073.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值