Difference between revisions of "Cpp Coding Standards/Class Construction, Destruction and Copying"
From Apache OpenOffice Wiki
Line 1: | Line 1: | ||
− | + | Topic-Id: '''CLSINIT''' | |
+ | |||
Special issues of constructors, copying and destructors. | Special issues of constructors, copying and destructors. | ||
---- | ---- | ||
=== Summary === | === Summary === | ||
− | ==== | + | ==== No Virtuals in Constructor or Destructor ==== |
− | 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]] |
+ | |||
+ | ==== Constructor Initialization Section ==== | ||
Use the constructors initialization section to initialize your members. | Use the constructors initialization section to initialize your members. | ||
− | ==== | + | [[/InitSect|Details]] |
+ | ==== Obvious Copyability ==== | ||
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]] |
+ | |||
+ | ==== 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]] | ||
+ | |||
---- | ---- | ||
=== Related Rules === | === Related Rules === | ||
− | * [[../ | + | * [[../Class Design#No Implicit Conversions| Class Design/No Implicit Conversions]] |
− | * [[../ | + | * [[../Error Handling#Which Functions Never Fail|Error Handling/Which Functions Never Fail]] |
− | * [[../ | + | * [[../Virtual Classes#Right Destructor|Virtual Classes/Right Destructor]] |
− | * [[../ | + | * [[../Virtual Classes#Safe Copying|Virtual Classes/Safe Copying]] |
− | + | ||
− | + | ||
---- | ---- | ||
[[Category:Coding Standards]] | [[Category:Coding Standards]] |
Revision as of 16:31, 28 November 2006
Topic-Id: CLSINIT
Special issues of constructors, copying and destructors.
Contents
Summary
No Virtuals in Constructor or Destructor
Don't call your own class' virtual functions in a constructor or destructor.
Constructor Initialization Section
Use the constructors initialization section to initialize your members.
Obvious Copyability
Make it obvious if the class is intended to be copied. Forbid copying otherwise.
Copy and Assign Consistently
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