new delete

#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
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务