Suppose I have one vector as follows:and I want to make a new vector containing, say, the first 5 elements of v1. Why is it OK to doCode:vector<int> v1; for(int i = 0; i < 10; ++i) { v1.push_back(i+1); vector<int>::iterator next; }and OK to doCode:vector<int> v2(&v1[0], &v1[5]); for(next = v2.begin() ; next != v2.end(); ++next ) { cout << *next << " "; } cout << "\n";but not OK to doCode:next = v1.begin(); vector<int> v2(next, next+5);Code:vector<int> v2(v1.begin(), &v1[5]);



LinkBack URL
About LinkBacks



