c++的核心准则
Posted ejinxian
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c++的核心准则相关的知识,希望对你有一定的参考价值。
C++ Core Guidelines 是一份不断改进的活文件。是一个开源(代码)项目,发布版是0.8。从这个项目复制、使用、修改和创作衍生作品的许可。对该项目进行贡献需要同意贡献者许可证。详细信息请参见附带的LICENSE文件。我们将这个项目提供给“友好的用户”使用、复制、修改和派生,希望得到建设性的输入。
特性:
- 规则集还没有完全检查其完整性、一致性或可执行性。
- 标记已知的缺失信息
- 更新引用部分;许多c++ 11之前的源代码都太老了。
- 有关最新的待办事项列表,请参阅:待办事项:未分类的原始规则
阅读本指南的范围和结构的解释,或者直接进入:
- In: Introduction
- P: Philosophy
- I: Interfaces
- F: Functions
- C: Classes and class hierarchies
- Enum: Enumerations
- R: Resource management
- ES: Expressions and statements
- Per: Performance
- CP: Concurrency and parallelism
- E: Error handling
- Con: Constants and immutability
- T: Templates and generic programming
- CPL: C-style programming
- SF: Source files
- SL: The Standard Library
支持部分:
- A: Architectural ideas
- NR: Non-Rules and myths
- RF: References
- Pro: Profiles
- GSL: Guidelines support library
- NL: Naming and layout rules
- FAQ: Answers to frequently asked questions
- Appendix A: Libraries
- Appendix B: Modernizing code
- Appendix C: Discussion
- Appendix D: Supporting tools
- Glossary
- To-do: Unclassified proto-rules
特定语言特性的规则:
- assignment: regular types – prefer initialization – copy – move – other operations – default
class
: data – invariant – members – helpers – concrete types – ctors, =, and dtors – hierarchy – operatorsconcept
: rules – in generic programming – template arguments – semantics- constructor: invariant – establish invariant – throw – default – not needed – explicit – delegating – virtual
- derived
class
: when to use – as interface – destructors – copy – getters and setters – multiple inheritance – overloading – slicing – dynamic_cast - destructor: and constructors – when needed? – must not fail
- exception: errors – throw – for errors only – noexcept – minimize try – what if no exceptions?
for
: range-for and for – for and while – for-initializer – empty body – loop variable – loop variable type ???- function: naming – single operation – no throw – arguments – argument passing – multiple return values – pointers – lambdas
inline
: small functions – in headers- initialization: always – prefer – lambdas – in-class initializers – class members – factory functions
- lambda expression: when to use
- operator: conventional – avoid conversion operators – and lambdas
public
,private
, andprotected
: information hiding – consistency – protectedstatic_assert
: compile-time checking – and conceptsstruct
: for organizing data – use if no invariant – no private memberstemplate
: abstraction – containers – conceptsunsigned
: and signed – bit manipulationvirtual
: interfaces – not virtual – destructor – never fail
以上是关于c++的核心准则的主要内容,如果未能解决你的问题,请参考以下文章