title: Allowing access to private members
body: <p>This question is somewhat a continuation of <a href="https://stackoverflow.com/questions/15100515/inherit-private-members-from-base-class#comment21258644_15100515">this one</a> I've posted.</p>
  
  <p><strong>What I was trying to do</strong>: my point was to allow access to private members of a base class <code>A</code> in a derived class <code>B</code>, with the following restraints:</p>
  
  <ul>
  <li>what I want to access is a structure -- an <code>std::map&lt;&gt;</code>, actually --, not a method;</li>
  <li>I <strong>cannot</strong> modified the base class;</li>
  <li>base class <code>A</code> has no templated method I may overload as a backdoor alternative -- and I would not add such method, as it would be going <em>against</em> the second restraint.</li>
  </ul>
  
  <p>As a possible solution, I have been pointed to litb's solution (<a href="https://stackoverflow.com/a/3173080/1655939">post</a> / <a href="http://bloglitb.blogspot.de/2011/12/access-to-private-members-safer.html" rel="nofollow noreferrer">blog</a>), but, for the life of me, I haven't been able to reach an understanding on what is done in these posts, and, therefore, I could not derive a solution to my problem.</p>
  
  <p><strong>What I am trying to do</strong>: The following code, from litb's solution, presents an approach on how to access private members from a class/struct, and it happens to cover the restrictions I've mentioned.</p>
  
  <p>So, I'm trying to rearrange this one code:</p>
  
  <pre><code>template&lt;typename Tag, typename Tag::type M&gt;
  struct Rob { 
    friend typename Tag::type get(Tag) {
      return M;
    }
  };
  
  // use
  struct A {
    A(int a):a(a) { }
  private:
    int a;
  };
  
  // tag used to access A::a
  struct A_f { 
    typedef int A::*type;
    friend type get(A_f);
  };
  
  template struct Rob&lt;A_f, &amp;A::a&gt;;
  
  int main() {
    A a(42);
    std::cout &lt;&lt; "proof: " &lt;&lt; a.*get(A_f()) &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>To something that would allow me to do the following -- note I'm about to inherit the class, as the entries in the <code>std::map&lt;&gt;</code> are added right after the initialization of the derived class <code>B</code>, i.e., the <code>std::map&lt;&gt;</code> isn't simply a static member of class <code>A</code> with a default value, so I need to access it from a particular instance of <code>B</code>:</p>
  
  <pre><code>// NOT MY CODE -- library &lt;a.h&gt;
  class A {
  private:
      std::map&lt;int, int&gt; A_map;
  };
  
  // MY CODE -- module "b.h"
  # include &lt;a.h&gt;
  class B : private A {
  public:
      inline void uncover() {
          for (auto it(A_map.begin()); it != A_map.end(); ++it) {
              std::cout &lt;&lt; it-&gt;first &lt;&lt; " - " &lt;&lt; it-&gt;second &lt;&lt; std::endl;
          }
      }
  };
  </code></pre>
  
  <p><strong>What I'd like as an answer</strong>: I'd really <em>love</em> to have the above code working -- after the appropriate modifications --, but I'd be <strong>very</strong> content with an explanation on what is done in the first code block -- the one from litb's solution.</p>