Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To answer that question, I'd like to describe member's accessors first in my own words. If you already know this, skip to the heading "next:".</p> <p>There are three accessors that I'm aware of: <code>public</code>, <code>protected</code> and <code>private</code>. </p> <p>Let:</p> <pre><code>class Base { public: int publicMember; protected: int protectedMember; private: int privateMember; }; </code></pre> <ul> <li>Everything that is aware of <code>Base</code> is also aware that <code>Base</code> contains <code>publicMember</code>.</li> <li>Only the children (and their children) are aware that <code>Base</code> contains <code>protectedMember</code>.</li> <li>No one but <code>Base</code> is aware of <code>privateMember</code>.</li> </ul> <p>By "is aware of", I mean "acknowledge the existence of, and thus be able to access".</p> <h2>next:</h2> <p>The same happens with public, private and protected inheritance. Let's consider a class <code>Base</code> and a class <code>Child</code> that inherits from <code>Base</code>.</p> <ul> <li>If the inheritance is <code>public</code>, everything that is aware of <code>Base</code> and <code>Child</code> is also aware that <code>Child</code> inherits from <code>Base</code>.</li> <li>If the inheritance is <code>protected</code>, only <code>Child</code>, and its children, are aware that they inherit from <code>Base</code>.</li> <li>If the inheritance is <code>private</code>, no one other than <code>Child</code> is aware of the inheritance.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload