new delete

2019-03-22  本文已影响0人  去年匆匆今年匆匆
#include <iostream>
#include <cstdlib>
using namespace std;  
class shape 
{ 
public:
 char x;
    shape(char m) 
    {  
     x=m;
     cout << "构造"<<endl;
     cout <<x<<endl;
    } 
    ~shape() 
    {  
     cout << "析构"<<endl;
     cout<<x<<endl;
    } 
}; 
int main() 
{ 
    shape a('a'); 
    shape b('b');
    shape* c = new shape('c');
    delete c;
    system("pause");
    return 0; 
}
构造
a
构造
b
构造
c
析构
c
请按任意键继续. . .
析构
b
析构
a
上一篇 下一篇

猜你喜欢

热点阅读