title: Using abstract classes as argument for function in C++
body: <p>I have a simple interface that provides Visitor pattern for graphs in DFS</p>
  
  <pre><code>class DFSVisitor {
  public:
      virtual void enterVertex(DirectedGraph::VertexIndex vertex) = 0;
      virtual void leaveVertex(DirectedGraph::VertexIndex vertex) = 0;
      virtual void checkEdge(DirectedGraph::VertexIndex vertex, DirectedGraph::VertexIndex to) = 0;
  };
  </code></pre>
  
  <p>And I got function that uses instance of mentioned class:</p>
  
  <pre><code>void dfs(VertexIndex vertex, std::vector&lt;bool&gt;&amp; used, DFSVisitor&amp; visitor) const {
      //some code
  }
  </code></pre>
  
  <p>The problem is that I'm getting compile time error:</p>
  
  <pre><code>error c2259 cannot instantiate abstract class
  </code></pre>
  
  <p>I understand that I can just put some easy implementation into this class, even empty body would help, but I need to have this class abstract due to review conditions.<br/></p>
  
  <p>So how could I avoid this problem? </p>
  
  <p><strong>Update:</strong>
  Code of VertexIndex:</p>
  
  <pre><code>typedef size_t VertexIndex;
  </code></pre>
  
  <p>Added to clarify code above. <br/></p>
  
  <p><strong>Update</strong>
  Thanks to everyone, I recognized the problem.
  In function definition I needed only to change from reference to pointer</p>
  
  <pre><code>void dfs(VertexIndex vertex, std::vector&lt;bool&gt;&amp; used, DFSVisitor* visitor) const {
      //some code
  }
  </code></pre>
  
  <p>Because I can't work with reference of abstract class, only with pointer this code would. work.</p>