title: Accessing protected member functions from test code in C++
body: <p>I've been racking my brain trying to think of the best way to access a protected member function from some test code in C++, here's my problem:</p>
  
  <pre><code>//in Foo.h 
  Class Foo
  {
  protected:
      void DoSomething(Data data);
  }
  
  //in Blah.h
  Class Blah
  {
  public:
      Foo foo;
      Data data; 
  };
  
  //in test code...
  Blah blah;
  blah.foo.DoSomething(blah.data); // Here's my problem!
  </code></pre>
  
  <p>Some possible solutions so far:
  <li>Make the test code class a friend of Foo, but this pollutes Foo with test code</li>
  <li>Make DoSomething a public function</li>
  <li>I've looked at creating a test wrapper for Foo, as suggested in <a href="https://stackoverflow.com/questions/1127616/what-is-the-best-way-to-unit-test-a-protected-method-in-c">this post</a>, however this won't work as Blah contains the instance of Foo.  </p>
  
  <p>All advice/insight/opinions are most welcome!  </p>
  
  <p>Thanks </p>