c++ - Using RAII with a character pointer -
I see a lot of RAI Examples classes that wrap around file handles.
I have tried to adapt them without examples of luck without a character pointer.
The library I am using is a task that detects a letter indicator (such as get_me_a_string (char ** x)). This task allocates memory for that letter indicator and leaves it to clean the end user's library in its code.
So, I have a code that looks like this ...
four * one = zero; Char * b = NULL; Char * c = NULL; Get_me_a_string (& amp; a); If (a == NULL) {return; } Get_me_a_beer (& amp; amp; b); If (B == tap) {if (a! = Null) {free (a); } Return; } Get_me_something (& amp; c); If (c == NULL) {if (a! = NULL) {free (a); } If (b! = Null) {free (b); } Return; } If (a! = NULL) {free (A); } If (b! = Null) {free (b); } If (a! = NULL) {free (b); }
It seems that Raii is the answer to this disturbance which is above me. I provide a simple C ++ class which is a * * *
Thanks
Comments
Post a Comment