TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C++ Coding Standard

Rule:  OOP#005

This rule is Obsolete
Synopsis:Do use references for associations with cardinality '1' whenever possible
Severity Level:9
Category:Object Oriented Programming


If a class has a data member that represents an association with another class that has cardinality 1, that data member should be a reference if possible. This to reduce null pointer access violations. This rule does not apply when objects have an association with each other with both a cardinality of '1'. In this case, only the object that is created last and also destroyed first, could use a reference instead of a pointer. For example:

class CMyFileClass 
    CMyFileClass:: CMyFileClass(
        const CMyDirectoryClass& rDirectory);

    CMyDirectoryClass& m_rDirectory;

CMyFileClass::CMyFileClass(const CMyDirectoryClass& rDirectory)