hi.. if a class A contains an array of objects of another class B.. And in the constructor of A, while constructing objects of B, any one object throws an exception, then how can we guarantee to release all the memory acquired.. so that there is no memory leak..
It was asked in an interview recently.. I was not very sure how to answer this.. can any one help please...
In the above code, if in constructor of A, suppose 99 objects of B are constructed successfully, but 100th object throws exception, then how can we guarantee to release all the memory acquired by the other 99 objects?
It was asked in an interview recently.. I was not very sure how to answer this.. can any one help please...
Code:
class B{};
class A{
public:
B Array[100];
...
};
Comment