Software Development Methodology> Guidelines for new implementations>  Functions members

Release Information

Project: Siconos
Internal Release Number: 1.0
Last update: September 15, 2005
Related Documents:


next up previous

Function members

  • According to Eckel2000, (see details in chapter 8 p351 and chapter 11 p451), the first choice when passing an argument is to pass by const reference:
      - reference => avoid pass by value, which means copy of data by creation of a temporary variable (always const).
      - const        => input argument can be a const and particularly a return value of another function.
    This should be clear by reading the following example extracted from Eckel2000 p 352:
     	class X
    X f() {return X(); } // return by value
    void g1(X&) {} // Pass by non-const reference
    void g2(const X&) {} // Pass by const reference

    int main()
    {
    g1(f()); // Error: const temporary created by f()
    g2(f()); // ok
    }
  • Any member function that do not modify members should be declared as a const, this to allow const declaration for the class object.

next up previous