指针学习2--内存泄露
内存泄露的情形
:
1
#include <iostream>
2
using namespace std;
3
4
class 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
17
int main()
18
{
19
Stu *a = new Stu(20);
20
Stu *b = new Stu(30);
21
delete b;
22
return 0;
23
//or 其他隐藏异常
24
25
//导致内存泄露
26
delete a;
27
28
return 0;
29
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

转载请注明出处: http://www.cnblogs.com/liyuxia713/