Difference between revisions of "Cpp Coding Standards/TYPE"
From Apache OpenOffice Wiki
(formatting) |
m |
||
Line 1: | Line 1: | ||
− | + | == Type Safety (TYPE) == | |
''Casts and type recognition.'' | ''Casts and type recognition.'' | ||
Line 8: | Line 8: | ||
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. [[/CCast|-> Details]] | Don't use C-Style casts, but the C++ casts. [[/CCast|-> Details]] | ||
− | ==== Avoid <code>static_cast</code> on Pointers <span id="StacaPtr">(StacaPtr)</span> ==== | + | ===== 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]] | Use dynamic_cast instead of static_cast when treating pointers polymorphically. [[/StacaPtr|-> Details]] | ||
− | |||
---- | ---- | ||
− | === Related Rules === | + | ==== Related Rules ==== |
− | * [[../CLSDESIGN#NoConv |CLSDESIGN:NoConv]] | + | * 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