<p>Having a vector containing pointers to objects then using the clear function doesn't call the destructors for the objects in the vector. I made a function to do this manually but I don't know how to make this a generic function for any kind of objects that might be in the vector.</p>

<pre><code>void buttonVectorCleanup(vector&lt;Button *&gt; dVector){
    Button* tmpClass;
    for(int i = 0; i &lt; (int)dVector.size(); i++){
        tmpClass = dVector[i];

        delete tmpClass;
    }
}
</code></pre>

<p>This is the function I have that works fine for a specific type of object in the vector but I'd like a single function that could take any kind of vector with object pointers.</p>

The best thing to do is use smart pointers, such as from
Boost
.  Then the objects will be deleted automatically.
Or you can make a template function
```
```
template <class T>
void vectorCleanup(vector<T *>& dVector){
    T* tmpClass;
    for(vector<T*>::size_type i = 0; i < dVector.size(); i++){
        tmpClass = dVector[i];

        delete tmpClass;
    }
```
```
}