2 ms·
I'm surprised he didn't give an even simpler reason, which is that algorithms were designed to work with pointers as well as objects. You can't call begin() or
by makecheck 15y ago
I'm surprised he didn't give an even simpler reason, which is that algorithms were designed to work with pointers as well as objects.
You can't call begin() or end() on a pointer. And although you can figure out the end of a stack-allocated C array, you can't do it for a heap-based array. For example, with "x = new int[30]" and a call like "sort(x, ...)", you may know the size of "x" but the algorithm can't know. The solution is to make algorithms accept a form like "sort(x, x + 30, ...)".
Of course now, with things like std::array in the standard, there are fewer reasons to care about pointers than before.