class MyElem;
typedef std::vector<MyElem*> MyElems;
To clear a memory taken by such vector I am using this code:
1 2 3 4 5 6 7 8 9
void deleteElems(MyElems &Elems)
{
for (auto i = Elems.begin(); i != Elems.end(); ++i)
{
delete((*i));
}
Elems.clear();
}
Recently I've introduced another vector:
1 2 3
class MyEntity;
typedef std::vector<MyEntity*> MyEntities;
I could introduce deleteEntities function but I thought to use templates here.
That would be great, to use one function to handle multiple cases. However, I would like to avoid a cryptic error message in case when I pass wrong parameter to the function template. So I would like to contrain somehow to types that can be passed as parameters.
How can I write a function template which accepts only vectors of pointers? Is it possible? I am using C++ 11, no boost library.