Here is two sample classes and the implementation of destructor for class Foo
. Why is m_barvec1
implemented as the way it is in the destructor and what does vector<Bar *> m_barvec1
mean?
class Bar {
public:
Bar() : m_arr(new int[100]) {}
~Bar();
int m_x;
std::list<int> m_list;
int* m_arr;
};
class Foo {
public:
Foo() : m_barvec3(new std::vector<Bar>()) {}
~Foo();
Bar m_bar;
std::vector<Bar *> m_barvec1;
std::vector<Bar> m_barvec2;
std::vector<Bar> *m_barvec3;
};
Foo::~Foo() {
for (size_t i = 0; i < m_barvec1.size(); i++) {
delete m_barvec1[i];
}
delete m_barvec3;
}