Difference between revisions of "Cpp Coding Standards/TYPE"
From Apache OpenOffice Wiki
m (Cpp Coding Standards/Type Safety moved to Cpp Coding Standards/TYPE: consistency) |
(formatting) |
||
Line 1: | Line 1: | ||
− | + | === Type Safety (TYPE) === | |
+ | ''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. [[/NoRepr|-> Details]] | ||
− | + | ===== No <code>switch</code> on Types <span id="NoSwitch">(NoSwitch)</span> ===== | |
− | === | + | Don't use switch, when the cases represent types. Prefer polymorphism. [[/NoSwitch|-> Details]] |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | Don't use switch, when the cases represent types. Prefer polymorphism. | + | |
− | + | ||
− | [[/NoSwitch|Details]] | + | |
==== No C-Style Casts <span id="CCast">(CCast)</span> ==== | ==== No C-Style Casts <span id="CCast">(CCast)</span> ==== | ||
− | Don't use C-Style casts, but the C++ casts. | + | Don't use C-Style casts, but the C++ casts. [[/CCast|-> Details]] |
− | + | ||
− | [[/CCast|Details]] | + | |
− | + | ||
− | + | ||
− | + | ||
− | [[/StacaPtr|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 === | === Related Rules === | ||
− | * [[../ | + | * [[../CLSDESIGN#NoConv |CLSDESIGN:NoConv]] - No Implicit Conversions |
---- | ---- | ||
[[Category:Coding Standards]] | [[Category:Coding Standards]] |
Revision as of 19:04, 22 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
- CLSDESIGN:NoConv - No Implicit Conversions