Created
October 28, 2010 02:40
-
-
Save shihongzhi/650502 to your computer and use it in GitHub Desktop.
析构函数和构造函数的调用过程
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 <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