John Harrison wrote:
"Jay" <tw************@hotmail.com> wrote in message
news:7p*****************@fe3.columbus.rr.com...
<snip> If
I ever need to sort a dynamic array, I'll make it a Vector.
Actually you don't need to, all you need to do is modify your own array
class so that it uses iterators.
Or even with a C-style array:
-----------------
#include <algorithm>
#include <vector>
#include <iostream>
#include <iterator>
using namespace std;
int
main()
{
const unsigned int ARRAY = 5;
int array[ARRAY] = { 5, 2, 7, 9, 1 };
cout << "Before: ";
copy(array, array + ARRAY, ostream_iterator<int>(cout, " "));
cout << '\n';
sort(array, array + ARRAY);
cout << "After: ";
copy(array, array + ARRAY, ostream_iterator<int>(cout, " "));
cout << '\n';
return 0;
}
---------------
However, that's not really the point. The best reason to not reinvent
the wheel in this case is that new people coming to the project will
already know how to use a vector (or you shouldn't have hired them). No
one will know how to use your home-grown array class, and they will
waste time not only trying to learn it, but will spend time wondering
why the designer felt it necessary to roll his own.
If you bear in mind that you should be writing your code for the next
person who has to look at it, I think your choice is clear.
--
Adam Fineman
(Reverse domain name to reply.)