title: How to write a generic print for vector of vectors using c++
body: <p>My Initial implementation approach in .cpp is like the following:</p>
  
  <pre><code>using namespace std;
  ...
  template &lt;typename T&gt;
  void print2dvector(vector&lt;vector&lt;T&gt; &gt; v) {
      for(int i = 0; i &lt; v.size(); i++) {
          for(int j = 0; j &lt; v[i].size(); j++) {
              cout &lt;&lt; v[i][j] &lt;&lt; " ";
          }
          cout &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>The declaration in .h file is the following</p>
  
  <pre><code>template &lt;typename T&gt; void print2dvector(std::vector&lt;std::vector&lt;T&gt; &gt; v);
  </code></pre>
  
  <p>Here is how I use it,</p>
  
  <pre><code>print2dvector&lt;int&gt;(vec_of_vec);
  </code></pre>
  
  <p>The compile stage passes, but failed in linking stage. The error is the following:</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
    "void print2dvector&lt;int&gt;(std::__1::vector&lt;std::__1::vector&lt;int, std::__1::allocator&lt;int&gt; &gt;, std::__1::allocator&lt;std::__1::vector&lt;int, std::__1::allocator&lt;int&gt; &gt; &gt; &gt;)", referenced from:
     spiral_matrix_ii_Challenge::Execute() in spiral_matrix_ii.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>Please let me know if I miss anything conceptually in implementing this.</p>