Suppose there is this code:
class CFoo
{
public:
CFoo()
{
iBar = new CBar();
}
private:
CBar* iBar;
};
....
CFoo* foo = new CFoo();
When the above line is executed, first memory will be allocated to hold the CFoo object. But then if the line new CBar() throws an exception (due to lack of memory) does the system automatically deallocate the memory that was previously allocated to the CFoo object? I presume it must, but cannot find any explicit reference saying so. If it doesn't how can the memory be deallocated by the coder as it will not have been assigned to foo?