Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@randrews
Created January 26, 2013 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randrews/4645041 to your computer and use it in GitHub Desktop.
Save randrews/4645041 to your computer and use it in GitHub Desktop.
Proving that destructors get called.
#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