Iterating through vector using C++11 for() loops

The loop

for (auto i: AVLTree) { ... }

tries to make a copy of each element of the range in AVLTree.begin() and AVLTree.end(). Of course, std::unique_ptr<T> can’t be copied: there is only one std::unique_ptr<T> to each pointer. It wouldn’t really copy anything but rather steal it. That would be bad.

You want to use references instead:

for (auto& i: AVLTree) { ... }

… or, if you don’t modify them

for (auto const& i: AVLTree) { ... }

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)