By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,054 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,054 IT Pros & Developers. It's quick & easy.

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

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

int main()
int number;
vector <int> ranVec(5000);

void ranNum(vector <int> &ranVec)
unsigned seed = time(NULL);
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.begin(), ranVec.end());
Dec 2 '15 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 5K+
P: 9,197
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:
Expand|Select|Wrap|Line Numbers
  1. void ranNum(vector <int> &ranVec)
  2. {
  3.     unsigned int seed = (unsigned int) time(NULL);
  4.     srand(seed);
  6.     int size = ranVec.size();
  7.     for (int i = 0; i < size; i++)
  8.     {
  9.         ranVec[i] = rand();
  10.     }
  11. }
Dec 2 '15 #2

P: 2
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 :)
Dec 3 '15 #3

Expert Mod 5K+
P: 9,197
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.
Dec 3 '15 #4

Post your reply

Sign in to post your reply or Sign up for a free account.