initial value of reference to non-const must be an lvalue during my sorting equation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tmay3rdbase
    New Member
    • Dec 2015
    • 2

    initial value of reference to non-const must be an lvalue during my sorting equation

    My code is as follows:(other than the set up of my functions)

    int main()
    {
    int number;
    vector <int> ranVec(5000);
    ranNum(ranVec);
    sort(ranVec);
    }

    void ranNum(vector <int> &ranVec)
    {
    unsigned seed = time(NULL);
    srand(seed);
    for (int i = 0; i < ranVec.size(); i++)
    {
    ranVec[i] = rand();
    }
    }

    void sort(vector <int> &ranVec)
    {
    //I get the error on my ranVac before the decimal place
    //each time.
    sort(ranVec.beg in(), ranVec.end());
    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    I get no errors in the posted code. I did get a warning that time(NULL) does not return an unsigned int. Also in the loop ranVec.size() does not return a signed int.

    I fixed those:
    Code:
    void ranNum(vector <int> &ranVec)
    {
    	unsigned int seed = (unsigned int) time(NULL);
    	srand(seed);
    
    	int size = ranVec.size();
    	for (int i = 0; i < size; i++)
    	{
    		ranVec[i] = rand();
    	}
    }

    Comment

    • tmay3rdbase
      New Member
      • Dec 2015
      • 2

      #3
      to me it will not run the sort formula it gives me an overload on my vector half of it. ex: ranVec.begin()

      Thank you for responding :)

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        ranVec is your data. ranVec.begin() returns an iterator to the beginning of your data. This is not an overload. It is a vector member function. Similarly, revVec.end() is an iterator one position past the end of your data.

        Why do you say it won't run the sort? Your code ran OK for me, including the sort.

        Comment

        Working...