-
memory fault/leak
Can this code have a memory fault/leak?
Code:
class A {
public:
~A() {}
vector<B> b;
};
class B {
public:
~B() {}
map<C, string> c_map;
};
Class C {
}
main() {
C c1,c2,c3,c4;
B b1,b2;
b1.c_map(c1) = "c1";
b1.c_map(c2) = "c2";
b2.c_map(c3) = "c3";
b2.c_map(c4) = "c4";
A *a = new A();
a.b.push_back(b1);
a.b.push_back(b2);
delete a;
}
-
It doesn't have a memory leak.* Are you asking because of the empty destructor? Destructors of members are still called (automatically after user-defined destructor completes) - you can't change this feature of destructors.
*Because of the use of a dumb pointer and not catching exceptions, this code can (theoretically) leak, should either of the push_back's trigger an exception to be thrown.
-
However, it does have at least two syntax errors. Also, your map is either not a standard map, which means there could be memory leaks in there, or you have four more syntax errors.
-
Thank You, anon & Corned Bee, thanks for the reply