title: Visitor-Pattern in C++ in a Header-Only Environment
body: <p>I've currently trouble implementing the <a href="https://en.wikipedia.org/wiki/Visitor_pattern" rel="nofollow noreferrer">Visitor-Pattern</a> in a Header-Only library in C++.</p>
  
  <p>Consider following class which should support being visited by a visitor (no interface for simplicity reasions):</p>
  
  <pre><code>class Acceptor
  {
      void accept(Visitor* v)
      {
          v-&gt;visit(this);
      }
  };
  </code></pre>
  
  <p>Here is the interface for the visitors:</p>
  
  <pre><code>class Visitor
  {
      virtual void visit(Acceptor* t) = 0;
  };
  </code></pre>
  
  <p>In a Header-Only lib, Acceptor.hpp must include Visitor.hpp and Visitor.hpp must include Acceptor.hpp. Since both headers are protected by <a href="https://en.wikipedia.org/wiki/Include_guard" rel="nofollow noreferrer">Include-Guards</a>, the later one will fail. Using forward declarations won't solve the problem, too.  </p>