Created
August 10, 2020 01:40
-
-
Save domiyanyue/cc1899da38bd076e6691d051102ce47d to your computer and use it in GitHub Desktop.
RAII example 2
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 demo2(){ | |
A *a = new A; | |
int ra = a -> func(); | |
if(ra == 2) { | |
B *b = new B; | |
int rb = b->func(); | |
delete a; | |
delete b; | |
return rb; | |
} else if(ra == 1) { | |
C *c = new C; | |
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