Changes between Version 13 and Version 14 of CodingGuidelines


Ignore:
Timestamp:
Mar 29, 2012, 10:46:25 AM (13 years ago)
Author:
FrederikHeber
Comment:

added section on constructor's initialization list

Legend:

Unmodified
Added
Removed
Modified
  • CodingGuidelines

    v13 v14  
    163163
    164164This way we can control the verbosity of the code easily and we do not end up with many commented-out wasteland alike ''... //std::cout << "Variable bla is " << ...''.
     165
     166=== Use constructors initialization list properly === #code-good-bad-constructor-initialization
     167
     168Constructors may be given an initialization list, e.g.
     169{{{
     170class SomeClass {
     171 ...
     172 double test;
     173 ...
     174};
     175
     176SomeClass::SomeClass() :
     177  test(0.)
     178{}
     179
     180SomeClass::SomeClass(const double t) :
     181  test(t)
     182{}
     183}}}
     184This is more efficient that setting the value in the constructor's body because the constructor of ''test'' gets called with the correct value right away instead of default constructor and then assignment operator.