liyuxia713

蹒跚前行者

常用链接

统计

Algorithms

C++

最新评论

指针学习2--内存泄露

内存泄露的情形
 1#include <iostream>
 2using namespace std; 
 3
 4class Stu
 5{
 6   public:
 7         Stu(int m):var(m)
 8         {                  
 9                  cout << var <<" constructor called." << endl;
10         }
      
11          ~Stu() { cout << var << " destructor called." << endl;}         
12   private:
13          int var;            
14}
;
15
16
17int main()
18{
19    Stu *= new Stu(20); 
20    Stu *= new Stu(30);  
21    delete b;
22    return 0;
23    //or 其他隐藏异常
24
25    //导致内存泄露
26    delete a;
27
28    return 0;
29}

posted on 2010-04-18 12:06 幸运草 阅读(457) 评论(0)  编辑 收藏 引用 所属分类: C++


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理