I don't understand why variable i isn't known in a whole body of first for. How does defining variables in for's parentheses work ? (if do it with int i I still get errors)
void cardlike(vector<int> &v)
{
unsigned max_pos = 0;
int tmp;
for (unsigned i = 0; i < v.size(); i++);
{
for (unsigned j = 0; j < v.size() - i; j++)
if(v[j] > v[max_pos])
max_pos = j;
tmp = v[max_pos];
v[max_pos] = v[v.size() - i - 1];
v[v.size() - i - 1] = tmp;
}
}
This is what i get from g++ when i'm compiling it with -std=c++11:
sortvector.cpp:93:38: error: ‘i’ was not declared in this scope
for(unsigned j = 0; j < v.size() - i; j++)
^
sortvector.cpp:98:29: error: ‘i’ was not declared in this scope
v[max_pos] = v[v.size() - i - 1];
^