title: C++ subclass access
body: <p>I have a main class that is inherited by numerous subclasses. The inherited main class has to be at least protected in inheritance to prevent non-derivative classes from using or altering it via the subclasses.</p>
  
  <p>Is there a way to permit the various subclasses to alter each other's inherited main class variables, but without permitting public access to the main class? And without using the friend keyword given this would produce complicated code.</p>
  
  <p>In full context:</p>
  
  <p>I have a node class that add/remove nodes relative to it. There is a list class (and subclasses) that rely upon the node class, which means the node cannot be publicly accessible in-case it also breaks the class list. Node has to also be accessible to list helper classes.</p>
  
  <p>To ensure that occurs, I implemented node under protected inside another class, accessnode. All classes wanting rights to node inherit accessnode as protected (so the accessnode class isn't public). This means the helper and the list class/subclasses all gain access to node.</p>
  
  <p>The problem is, in order for TemplateList to copy CharList (a subclass of TemplateList) via read-only, it needs access to the nodes of CharList (to avoid using CharList's iterator) - the problem is, the nodes are protected (to prevent external, non-accessnode interference), and implementing a public method that grants access to the nodes would defeat the point.</p>
  
  <p>What I need is sideways inheritance, so all subclasses of type accessnode can access each other's node without granting access publicly.</p>
  
  <p>In short:</p>
  
  <p>(Protected)Node inside AccessNode.<br>
  TemplateList : Protected AccessNode.<br>
  CharList : Protected AccessNode.<br>
  TemplateList needs to access CharList's AccessNode.<br>
  AccessNode/Node cannot be public.</p>