title: Templates and Syntax
body: <p>Working on an algorithm to look at a STL container of STL strings (or other strings, making it general)</p>
  
  <p>Basically it loops through something like a std::list and returns the length of the longest beginning in common. It's for processing lists of files, like this:</p>
  
  <pre>
  C:\Windows\System32\Stuff.exe
  C:\Windows\Things\InHere.txt
  C:\Windows\Foo\Bar.txt
  </pre>
  
  <p>This should return 11, because "<code>C:\Windows\</code>" is in common.</p>
  
  <p>Never written a templatized function before, and my compiler is complaining. Here's my code:<br />
  Header:</p>
  
  <pre><code>// longestBegin.h -- Longest beginning subsequence solver
  template &lt;typename SequenceSequenceT, typename SequenceT, typename T &gt;
  size_t longestBegin(InputIterator firstCandidates, InputIterator lastCandidates);
  </code></pre>
  
  <hr>
  
  <p>Implementation:</p>
  
  <pre><code>// longestBegin.cpp -- Longest beginning subsequence solver
  #include &lt;stdafx.h&gt;
  
  template &lt;typename SequenceSequenceT, typename SequenceT, typename T &gt;
  size_t longestBegin(InputIterator firstCandidates, InputIterator lastCandidates)
  {
      SequenceT firstString = *firstCandidates;
      size_t longestValue = firstString.length();
      firstCandidates++;
      for(size_t idx = 0; idx &lt; longestValue; idx++)
      {
          T curChar = firstString[idx];
          for(InputIterator curCandidate = firstCandidates;curCandidate != lastCandidates; curCandidate++)
          {
              if ((*curCandidate)[idx] != curChar)
                  return idx - 1;
          }
      }
      return longestValue;
  }
  </code></pre>
  
  <p>I have a funny feeling I'm missing something fundamental here......</p>
  
  <p>The compiler bombs with the following error:</p>
  
  <pre><code>error C2998: 'size_t longestBegin' : cannot be a template definition
  </code></pre>
  
  <p>Any ideas? Thanks!</p>
  
  <p>Billy3</p>