Tuesday 15 January 2013

What is the difference between iterator with reference symbol, and without. (C++ loop) -



What is the difference between iterator with reference symbol, and without. (C++ loop) -

what difference between iterator & symbol, , 1 without it, seen in cases 1 , 2 in contrived illustration below?

when should utilize 1 or other?

#include <iostream> #include <vector> int main() { std::vector<int> v; v.push_back(1); v.push_back(2); // case 1: (auto & = v.begin(); != v.end(); ++i) { std::cout << *i << std::endl; } // case 2: (auto = v.begin(); != v.end(); ++i) { std::cout << *i << std::endl; } }

is creation of iterator object, , available in code block? i'm new iterators.

the difference first loop not compiled.:)

for (auto & = v.begin(); != v.end(); ++i) { std::cout << *i << std::endl; }

you created temporary object returned fellow member function begin , binded non-const reference.

c++ iterator auto

No comments:

Post a Comment