Difference between revisions of "Cpp Coding Standards/Class Construction, Destruction and Copying"
From Apache OpenOffice Wiki
m |
m |
||
Line 5: | Line 5: | ||
=== Summary === | === Summary === | ||
− | ==== <span id="NoVirt"> | + | |
+ | ==== No Virtual Calls in Constructor or Destructor <span id="NoVirt">(NoVirt)</span> ==== | ||
Don't call your own class' virtual functions in a constructor or destructor. | Don't call your own class' virtual functions in a constructor or destructor. | ||
[[/NoVirt|Details]] | [[/NoVirt|Details]] | ||
− | ==== Constructor Initialization Section ==== | + | ==== Constructor Initialization Section <span id="InitSect">(InitSect)</span> ==== |
Use the constructors initialization section to initialize your members. | Use the constructors initialization section to initialize your members. | ||
[[/InitSect|Details]] | [[/InitSect|Details]] | ||
− | ==== Obvious Copyability ==== | + | ==== Obvious Copyability <span id="ObvCopy">(ObvCopy)</span> ==== |
Make it obvious, if the class is intended to be copied. Forbid copying otherwise. | Make it obvious, if the class is intended to be copied. Forbid copying otherwise. | ||
[[/ObvCopy|Details]] | [[/ObvCopy|Details]] | ||
− | + | ==== Copy and Assign Consistently <span id="CopyAssign">(CopyAssign)</span> ==== | |
− | ==== Copy and Assign Consistently ==== | + | |
Declare copy and assignment operators consistently – either both, or none. | Declare copy and assignment operators consistently – either both, or none. | ||
[[/CopyAssign|Details]] | [[/CopyAssign|Details]] | ||
− | |||
---- | ---- | ||
=== Related Rules === | === Related Rules === |
Revision as of 11:36, 29 November 2006
Topic-Id: CLSINIT
Special issues of constructors, copying and destructors.
Contents
Summary
No Virtual Calls in Constructor or Destructor (NoVirt)
Don't call your own class' virtual functions in a constructor or destructor.
Constructor Initialization Section (InitSect)
Use the constructors initialization section to initialize your members.
Obvious Copyability (ObvCopy)
Make it obvious, if the class is intended to be copied. Forbid copying otherwise.
Copy and Assign Consistently (CopyAssign)
Declare copy and assignment operators consistently – either both, or none.
Related Rules
- Class Design/No Implicit Conversions
- Error Handling/Which Functions Never Fail
- Virtual Classes/Right Destructor
- Virtual Classes/Safe Copying