resource acquisition is initialization "RAII"
- by hitech
in the example below
class X{
int *r;
public:
X(){cout<< X is created ; r new int[10]; }
~X(){cout<< X is destroyed ; delete [] r; }
};
class Y
{
public:
Y(){ X x; throw 44; }
~Y(){cout<< Y is destroyed ;}
};
I got this example of RAII from one site and ave some doubts. please help.
in the contructor of x we are not considering the scenation "if the memory allocation fails" .
Here for the destructor of Y is safe as in y construcotr is not allocating any memory. what if we need to do some memory allocation also in y constructor?