How to clean up class member of pointer to vector of pointers to a class?
<p>I have a class called Foo which has a member that is a pointer to a vector of pointers to another class called Bar. I initialise it in the constructor but I'm not sure how to deallocate it in the destructor. I'm still learning. Would appreciate your help. The reason for having this member is so that the scope persists beyond that method i.e. beyond the stack. Thanks.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;

using namespace std;

class Bar {};

class Foo {
public:
    Foo() {
        bars = new vector&lt;Bar*&gt;*[10];

        for (int i = 0; i &lt; 10; i++) {
            bars[i]-&gt;push_back(new Bar());
        }
    }

    ~Foo () {
        for (int i = 0; i &lt; 10; i++) {
            // TODO: how to clean up bars properly?
        }
    }

private:
    vector&lt;Bar*&gt;** bars;
};

int main () {
    new Foo();
    return 0;
}
</code></pre>

<p><strong>Update</strong>: I appreciate the feedback on all fronts. I'm new to C and C++. Basically I wanted a 2d structure as a class member that would persist for the lifetime of the class. The reason the outer structure is an array is because I know how big it needs to be. Otherwise I was previously using vector of vectors.</p>
