Skip to content

Instantly share code, notes, and snippets.

@shihongzhi
Created October 28, 2010 02:40
Show Gist options
  • Save shihongzhi/650502 to your computer and use it in GitHub Desktop.
Save shihongzhi/650502 to your computer and use it in GitHub Desktop.
析构函数和构造函数的调用过程
#include <iostream>
using namespace std;
struct Pig
{
Pig()
{
call();
}
~Pig()
{
call();
}
virtual void call(void)
{
cout<<"Pig\n";
}
};
struct SmallPig:public Pig
{
virtual void call(void)
{
cout<<"Small Pig\n";
}
};
int main(int argc,char* argv[])
{
Pig* p=new SmallPig;
p->call();
delete p;
getchar();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment