Difference between revisions of "Cpp Coding Standards/TYPE"

From Apache OpenOffice Wiki
Jump to: navigation, search
m
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
Topic-Id: TYPE
+
== 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. [[/NoRepr|-> Details]]
  
----
+
===== No <code>switch</code> on Types <span id="NoSwitch">(NoSwitch)</span> =====
=== Summary ===
+
Don't use switch, when the cases represent types. Prefer polymorphism. [[/NoSwitch|-> Details]]
==== 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 C-Style Casts <span id="CCast">(CCast)</span> ====
+
Don't use C-Style casts, but the C++ casts.
+
 
+
[[/CCast|Details]]
+
 
+
==== Avoid static_cast on Pointers <span id="StacaPtr">(StacaPtr)</span> ====
+
Use dynamic_cast instead of  static_cast when treating pointers polymorphically.
+
 
+
[[/StacaPtr|Details]]
+
 
+
==== No switch on Types <span id="NoSwitch">(NoSwitch)</span> ====
+
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 ===
+
==== Related Rules ====
* [[../Class Design#NoConv |CLSDESIGN:NoConv]] - No Implicit Conversions
+
* No Implicit Conversions [[../CLSDESIGN#NoConv|-> CLSDESIGN:NoConv]]
  
 
----
 
----
 
[[Category:Coding Standards]]
 
[[Category:Coding Standards]]

Latest revision as of 09:30, 23 May 2007

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


Personal tools