AutosarC++18_03-M11.0.1

Member data in non-POD class types shall be private

Required inputs: IR

Public data members could be modified by other types in a way that violates the invariants of the class. Data members should be encapsulated: they should be declared as private, and accessor functions should be declared to allow other classes access to the data members.
Example
class C
{
private:
    std::string m_member;

public:
    const std::string& member()
    {
        return m_member;
    }
    void member(const std::string& new_value)
    {
        assert(new_value.size() > 0);
        m_member = new_value;
    }
};
See Also
Rule Miscellaneous-NoReferenceToPrivateDataMember

Note

For legal reasons, this rule’s description is not part of the public documentation.