title: C++ header dependency propagation - how to limit it?
body: <p>I have a repeating dilemma while constructing a class in C++. I'd like to construct the class without propagating its internal dependencies outside.</p>
  <p>I know I have options like:</p>
  <ol>
  <li>Use pimpl idiom</li>
  <li>Use forward declaration and only reference or smart pointers in header</li>
  </ol>
  <pre><code>// header
  
  class Forwarded;    // I don't want to include Forwarded.h to not propagete it 
  
  class MyNewClass {
  private:
     std::unique_ptr&lt;Forwarded&gt; mForwareded;
     void method1UsesForwarded();
     void method2UsesForwarded();
  public:
     void doSomeAction();
  };
  </code></pre>
  <pre><code>// cpp
  #include &quot;Forwarded.h&quot;
  void MyNewClass::doSomeAction() {
     method1UsesForwarded();
     method2UsesForwarded();
  }
  
  void MyNewClass::method1UsesForwarded() { /* implementation */ }
  void MyNewClass::method2UsesForwarded() { /* implementation */ }
  </code></pre>
  <ol start="3">
  <li>Create another class or helper file which uses those files which I don't want to propagate further</li>
  </ol>
  <pre><code>// header
  
  class MyNewClass {
  public:
     void doSomeAction();
  };
  
  </code></pre>
  <pre><code>// cpp
  #include &quot;helper.h&quot;
  void MyNewClass::doSomeAction() {
      Forwarded f;
      method1UsesForwarded(f);
      method2UsesForwarded(f);
  }
  </code></pre>
  <pre><code>// helper.h
  #include &quot;Forwarded.h&quot;
  void method1UsesForwarded(Forwarded &amp; f);
  void method2UsesForwarded(Forwarded &amp; f);
  </code></pre>
  <pre><code>// helper.cpp
  #include &quot;helper.h&quot;
  void method1UsesForwarded(Forwarded &amp; f) {
      //implemntation
  }
  void method2UsesForwarded(Forwarded &amp; f) {
      //implemntation
  }
  
  </code></pre>
  <p>Is there any other option? I don't like any of the above solutions because they provide some additional complication. The best option for me would be creation of <code>Forwarded</code> as normal private member and somehow not propagate it further :-)</p>