home > resources > c++ coding standard > online version

Reference Variables and Functions Returning References

  • References should be prepended with 'r'.
  • Place the & close to the variable name not the reference type when working with reference variables. With function declarations, the & should be close to the reference type.
  • Functions returning non const references should be prepended with 'r' to make it clear that a modifiable is being returned.


  • The difference between variable types is clarified.
  • It establishes the difference between a method returning a modifiable object and the same method name returning a non-modifiable object.

Example 2-9. Reference Variables and Functions Returning References Example

class Test
    void                doSomething(StatusInfo &rStatus);
    StatusInfo&         rStatus();
    const StatusInfo&   status() const;

    StatusInfo &mrStatus;