M
Michael Domenic DiBernardo
I posted this on comp.std.c++ because it seemed a more appropriate
question for that forum, but I'm more or less in a hurry and so I decided
to toss it out here as well:
How might I declare a function that takes a forward_iterator as a
parameter? I want a generic function that will iterate over a given
forward iterator and free all of the pointers contained therein.
The gist:
#include <iterator>
void deleteAll(std::forward_iterator begin, std::forward_iterator end) {
while (begin != end) {
delete *begin;
++begin;
}
}
Silly usage scenario (assuming existence of class MyObj):
vector<MyObj*> v;
v.push_back(new MyObj());
v.push_back(new MyObj());
v.push_back(new MyObj());
deleteAll(v.begin(), v.end());
Any tips or references would be greatly appreciated!
Thanks,
-M.D.
question for that forum, but I'm more or less in a hurry and so I decided
to toss it out here as well:
How might I declare a function that takes a forward_iterator as a
parameter? I want a generic function that will iterate over a given
forward iterator and free all of the pointers contained therein.
The gist:
#include <iterator>
void deleteAll(std::forward_iterator begin, std::forward_iterator end) {
while (begin != end) {
delete *begin;
++begin;
}
}
Silly usage scenario (assuming existence of class MyObj):
vector<MyObj*> v;
v.push_back(new MyObj());
v.push_back(new MyObj());
v.push_back(new MyObj());
deleteAll(v.begin(), v.end());
Any tips or references would be greatly appreciated!
Thanks,
-M.D.