Difference between revisions of "Cpp Coding Standards/TYPE"
From Apache OpenOffice Wiki
m |
|||
(7 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | == Type Safety == | + | == Type Safety (TYPE) == |
− | Casts and type recognition | + | ''Casts and type recognition.'' |
− | + | ||
− | + | ||
− | ==== | + | ===== Types, not Representations <span id="NoRepr">(NoRepr)</span> ===== |
− | Rely on types, not on representations. Don't think in bits, don't memcpy non-PODs. | + | Rely on types, not on representations. Don't think in bits, don't memcpy non-PODs. [[/NoRepr|-> Details]] |
− | ==== | + | ===== No <code>switch</code> on Types <span id="NoSwitch">(NoSwitch)</span> ===== |
− | Don't use | + | Don't use switch, when the cases represent types. Prefer polymorphism. [[/NoSwitch|-> Details]] |
− | ==== | + | ===== No C-Style Casts <span id="CCast">(CCast)</span> ===== |
− | + | Don't use C-Style casts, but the C++ casts. [[/CCast|-> Details]] | |
− | ==== | + | ===== Avoid <code>static_cast</code> on Pointers <span id="StacaPtr">(StacaPtr)</span> ===== |
− | + | Use dynamic_cast instead of static_cast when treating pointers polymorphically. [[/StacaPtr|-> Details]] | |
+ | ---- | ||
+ | ==== Related Rules ==== | ||
+ | * No Implicit Conversions [[../CLSDESIGN#NoConv|-> CLSDESIGN:NoConv]] | ||
− | |||
− | |||
− | |||
---- | ---- | ||
[[Category:Coding Standards]] | [[Category:Coding Standards]] |
Latest revision as of 09:30, 23 May 2007
Contents
Type Safety (TYPE)
Casts and type recognition.
Types, not Representations (NoRepr)
Rely on types, not on representations. Don't think in bits, don't memcpy non-PODs. -> Details
No switch
on Types (NoSwitch)
Don't use switch, when the cases represent types. Prefer polymorphism. -> Details
No C-Style Casts (CCast)
Don't use C-Style casts, but the C++ casts. -> Details
Avoid static_cast
on Pointers (StacaPtr)
Use dynamic_cast instead of static_cast when treating pointers polymorphically. -> Details
Related Rules
- No Implicit Conversions -> CLSDESIGN:NoConv