Difference between revisions of "Cpp Coding Standards/Class Construction, Destruction and Copying"
From Apache OpenOffice Wiki
m |
m |
||
Line 4: | Line 4: | ||
---- | ---- | ||
=== Summary === | === Summary === | ||
− | ==== No | + | |
+ | ==== <span id="NoVirt">No Virtual Calls in Constructor or Destructor</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 ==== | ||
Use the constructors initialization section to initialize your members. | Use the constructors initialization section to initialize your members. | ||
Line 14: | Line 14: | ||
[[/InitSect|Details]] | [[/InitSect|Details]] | ||
==== Obvious Copyability ==== | ==== 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]] | [[/ObvCopy|Details]] | ||
Line 22: | Line 22: | ||
[[/CopyAssign|Details]] | [[/CopyAssign|Details]] | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ---- | ||
---- | ---- |
Revision as of 16:41, 28 November 2006
Topic-Id: CLSINIT
Special issues of constructors, copying and destructors.
Contents
Summary
No Virtual Calls 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