指针学习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}



幸运草 2010-04-18 12:06 发表评论
原文地址:https://www.cnblogs.com/liyuxia713/p/2540792.html