title: C++ Error: Conversion to Non-Scalar Type
body: <p>I seem to be having a peculiar error in the following code segment (ignore the excess header files and the blank main function, I just wanted to isolate this problem into a compileable .cpp file for posting here). It says error conversion from '[some type I defined]' to non-scalar type '[some type I defined]'.</p>
  
  <p>The code in this particular example is supposed to take a set of list of strings as one input parameter (named input), and a reference to a list of strings as another (named output) and calculate the longest common prefix list of strings from among the lists in input and store the result into output.</p>
  
  <p>The compiler error message (also included as a comment in the corresponding line is this:</p>
  
  <blockquote>
    <p>lcp.cpp:28:47: error: conversion from ‘<code>std::list&lt;std::basic_string&lt;char&gt; &gt;::const_iterator {aka std::_List_const_iterator&lt;std::basic_string&lt;char&gt; &gt;}</code>’ to non-scalar type ‘<code>std::list&lt;std::basic_string&lt;char&gt; &gt;::iterator {aka std::_List_iterator&lt;std::basic_string&lt;char&gt; &gt;}</code>’ requested</p>
  </blockquote>
  
  <p>And here is the actual program:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sstream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;set&gt;
  #include &lt;map&gt;
  #include &lt;list&gt;
  
  using namespace std;
  
  void getLongestCommonPrefix(set &lt;list &lt;string&gt; &gt; &amp; input, list &lt;string&gt; &amp; output)
  {
  
      set &lt;list &lt;string&gt; &gt; :: iterator it = input.begin();
  
      output = *it;
  
      for(; it != input.end(); ++it)
      {
          if(output.size() &gt; (*it).size())
          {
              list &lt;string&gt; :: iterator it1 = output.begin();
              advance(it1, (*it).size()-1);
              output.erase(it1, output.end());
          }
  
          list &lt;string&gt; :: iterator it1 = output.begin();
          list &lt;string&gt; :: iterator it2 = (*it).begin();  //lcp.cpp:28:47: error: conv    ersion from ‘std::list&lt;std::basic_string&lt;char&gt; &gt;::const_iterator {aka     std::_List_const_iterator&lt;std::basic_string&lt;char&gt; &gt;}’ to non-scalar type     ‘std::list&lt;std::basic_string&lt;char&gt; &gt;::iterator {aka     std::_List_iterator&lt;std::basic_string&lt;char&gt; &gt;}’ requested
  
          for(; it1 != output.end(); ++it1,++it2)
          {
              if(*it1 != *it2)
                  break;
          }
  
          output.erase(it1, output.end());
  
          if(!output.size())
              return;
      }
  }     
  
  int main()
  {
      return 0;
  }
  </code></pre>
  
  <p>I would love to hear from the experts here as to why and when this sort of error happens and what the work-around could be.</p>