Skip to content

Instantly share code, notes, and snippets.

@yuikns
Created March 23, 2014 12:14
Show Gist options
  • Save yuikns/9722299 to your computer and use it in GitHub Desktop.
Save yuikns/9722299 to your computer and use it in GitHub Desktop.
a test of gc
#include <cstdio>
class MyClass
{
public :
MyClass()
{
printf("my class inited\n");
}
~MyClass()
{
printf("my class destoried\n");
}
void call()
{
printf("my class be called\n");
}
};
MyClass& bar()
{
printf("bar start\n");
MyClass * mc = new MyClass();
printf("bar to return\n");
return *mc;
}
void foo()
{
printf("foo start\n");
MyClass & mc = bar();
mc.call();
printf("foo to end\n");
printf("my class call to delete\n");
delete &mc;
printf("my class call to delete done\n");
}
int main(int argc,char * argv[])
{
printf("main start\n");
foo();
printf("main to return\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment