Created
January 26, 2013 22:24
-
-
Save randrews/4645041 to your computer and use it in GitHub Desktop.
Proving that destructors get called.
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
#include <stdio.h> | |
class Thing{ | |
public: | |
int a; | |
Thing(int); | |
~Thing(); | |
}; | |
Thing::Thing(int _a){ | |
a = _a; | |
} | |
Thing::~Thing(){ | |
printf("Destructor called.\n"); | |
} | |
void foo(); | |
int main(){ | |
foo(); | |
} | |
void foo(){ | |
int i = 0; | |
for(Thing t=Thing(5); i < 10; i++){ | |
if(i == t.a) return; | |
} | |
printf("Never gets here.\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment