Last active
August 10, 2020 02:03
-
-
Save domiyanyue/3dd0b0dffb3f61b05f02190b183c49be to your computer and use it in GitHub Desktop.
RAII example 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int demo3(){ | |
A *a = new A; | |
int ra = a -> func(); | |
if(ra == 2) { | |
try { | |
B *b = new B; | |
} | |
catch (...) | |
{ | |
delete a; | |
throw; | |
} | |
int rb = b->func(); | |
delete a; | |
delete b; | |
return rb; | |
} else if(ra == 1) { | |
try { | |
C *c = new C; | |
} | |
catch (...) | |
{ | |
delete a; | |
throw; | |
} | |
int rc = c->func(); | |
delete a; | |
delete c; | |
return rc; | |
} | |
delete a; | |
return ra; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment