12 Sep
2002
12 Sep
'02
6:27 p.m.
From: "Mark Snelling" [...]
std::list
I can call the for_each algorithm on this list using my function above:
std::for_each(mylist.begin(), mylist.end(), &deleter);
and it will delete all of the objects pointed to in the list. Is it possible to convert deleter into a templated function:
template<class T> void deleter(T* t) { delete t; }
and pass that into the for_each algorithm?
Yes. You can use
std::for_each(mylist.begin(), mylist.end(), &deleter<Object>);
If this doesn't work, try
#include