title: c++ How to solve : Initial value of reference to non-const must be an lvalue
body: <p>I am writing a program that determines the prime factors of a range of numbers. In the program, the <code>startingNumber</code> and <code>endingNumber</code> of the range is indicated as a <code>std::pair</code>.</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  
  using namespace std;
  
  const long long MAX = 100000000; // One hundred million
  long long factor[MAX];
  
  
  pair&lt;const long long, const long long&gt; get_pair() // Gets user start and end number to establish range in vector.
  {
      long long largestNumber = 100000000;
      long long smallestNumber = 2;
      std::pair&lt;long long, long long&gt; p;
      cout &lt;&lt; "Enter a start number: ";
      cin &gt;&gt; p.first;
      while (p.first &lt; smallestNumber || p.first &gt; largestNumber || cin.fail()) {
          cin.clear();
          cin.ignore(1000, '\n');
          cout &lt;&lt; "That's not a valid choice. Please try again (" &lt;&lt; smallestNumber &lt;&lt; " - " &lt;&lt; largestNumber &lt;&lt; "): ";
          cin &gt;&gt; p.first;
      }
      cout &lt;&lt; "Enter a end number: ";
      cin &gt;&gt; p.second;
      while (p.second &lt; p.first || p.second &gt; largestNumber || cin.fail()) {
          cin.clear();
          cin.ignore(1000, '\n');
          cout &lt;&lt; "That's not a valid choice. Please try again (" &lt;&lt; p.first &lt;&lt; " - " &lt;&lt; largestNumber &lt;&lt; "): ";
          cin &gt;&gt; p.second;
      }
      cout &lt;&lt; endl;
  
      return make_pair(p.first, p.second);
  }
  
  vector&lt;long long&gt; rangeToVector(const long long &amp;startingNumber, const long long &amp;endingNumber) // creates vector of numbers from std::pair.
  {
      vector&lt;long long&gt; iterator;
  
      for (long long i = 1; i &lt;= ((10 - 1) + 1); i += 1) iterator.push_back((1-1)+i);
  
      return iterator;
  }
  void precalculate() // Calculates all of the prime numbers between 1 and MAX. Stores prime numbers from smallest to largest.
  {
      for (long long i = 1; i &lt; MAX; i++) { // stores 1 through Max in factor.
          factor[i] = i;
      }
  
      for (long long i = 2; i * i &lt; MAX; i++) if (factor[i] == i) { // If factor[i] is even.
          for (long long j = i + i; j &lt; MAX; j += i) {
              factor[j] = i;
          }
      }
  }
  </code></pre>
  
  <p>The above code works as intended. The code is then input into the follow function, I am unsure as to whether or works correctly(Since my function in main will not compile).</p>
  
  <pre><code>vector&lt;long long&gt; get_factors(vector&lt;long long&gt; &amp;vect) // performs calculation on rangeToVector[i] (determined by precalculate) until it is not divisible, then it returns those that were divided into the number as prime factors of the rangeToVector[i].
  {
      vector&lt;long long&gt; factors;
      for (auto i : vect)
      {
          while (vect[i] &gt; 1)
          {
              long long f = factor[vect[i]];
              factors.push_back(f);
              vect[i] /=f;
          }
      }
  
      sort(factors.begin(), factors.end()); // sorts the vector.
      factors.erase(unique(factors.begin(), factors.end()), factors.end()); // erases duplicates (requires sorted vector).
  
      return factors;
  }
  </code></pre>
  
  <p>In main (line 3), I receive the error underlining <code>rangeToVector</code>, <code>initial value of reference to non-const must be an lvalue</code>.</p>
  
  <pre><code>int main()
  {
      for (auto i : get_factors(rangeToVector(pairs.first, pairs.second))) // get_factors returns factors of numbers in vector rangeToVector
      {
          cout &lt;&lt; i &lt;&lt; " ";
      }
      system("pause");
      return 0;
  }
  </code></pre>
  
  <p>I attempted to make the values in <code>rangeToVector</code> constants, but this has not solved the problem. My question is, is my referencing incorrect? Should I pass the function differently? Or what can I do to the code to allow <code>get_factors</code> to take the factors of <code>rangeToVector[i]</code> in main on line 3. I am new to c++, so any help would be greatly appreciated. </p>