Changes between Version 24 and Version 25 of code/C++_styleguide
- Timestamp:
- Sep 21, 2008, 8:11:52 PM (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
code/C++_styleguide
v24 v25 8 8 9 9 Remember that any violation to the guide of course is allowed if it enhances readability. 10 11 ---- 12 13 == General == 14 === this === 15 Address all member variables and functions with the this-> operator: 16 {{{ 17 this->processData(this->data_); 18 }}} 19 20 === const === 21 Use const when it's possible. This includes variables and function declaration. Specially for function'''const''' is very important. Use it always if a function doesn't change the object. 22 {{{ 23 SomeClass.h: 24 int getSomeNumber() const; 25 26 SomeClass.cc: 27 int SomeClass::getSomeNumber() const 28 { 29 return myValue_; 30 } 31 }}} 32 Read [wiki:PerformanceTips#constfunctions this] for more information. 33 34 === Reference === 35 Use pass-by-reference over pass-by-value when possible: 36 {{{ 37 public: 38 void setPosition(const Vector3& position); 39 const Vector3& getPosition() const; 40 41 private: 42 Vector3 myPosition_; 43 }}} 44 Read [wiki:PerformanceTips#constreference this] for more information. 45 46 === Initialization === 47 * All class variables should be initialized to a sane value in the constructor. 48 * Prefer initialization to assignment in constructors. 49 * Initialize pointers with 0 or 'new ClassName'. 50 51 === Pointer === 52 * When a member value pointer is deleted, it should be set to 0. 53 * Don't forget to delete objects in the destructor if your class is responsible for the object. 54 55 === virtual === 56 * If a base class has virtual functions, derived classes should have the "virtual" keyword repeated for those functions. 57 * Don't use virtual functions in the constructor of the same class 58 59 ---- 10 60 11 61 == Files == … … 80 130 #endif /* _ClassName_H__ */ 81 131 }}} 132 133 ---- 82 134 83 135 == Comments == … … 172 224 }}} 173 225 226 ---- 227 174 228 == Naming Conventions == 175 229 … … 291 345 }}} 292 346 347 ---- 293 348 294 349 == Indentation == … … 311 366 }}} 312 367 368 ---- 369 313 370 == Whitespaces == 314 371 Use one space after each keyword and enclose operators with 2 of them: {{{ if (a + b < c) }}} … … 333 390 334 391 392 ---- 393 335 394 == Statements == 336 337 395 338 396 === Access Modifiers for Classes === … … 359 417 Only loop control statements must be included in the for() construction. 360 418 419 420 ---- 361 421 362 422 == Layout == … … 426 486 }}} 427 487 488 ---- 489 428 490 == Special Implementations == 429 491 === Use STL Libraries === 430 492 Use STL (standard template library) implementations of common abstract data structures like lists, arrays, stacks, queues, never implement your own! 431 493 432 == General Topics == 494 ---- 495 496 == Compiling == 433 497 * different build targets possible (for subprojects) 434 498 * different make options (make-dbg, make-opt) 435 499 * unit test supported (in debug mode) 436 500 * compiler mode: warnings being treated as errors 501 502 ---- 437 503 438 504 == Code Reviews ==