-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test1.cpp
46 lines (40 loc) · 908 Bytes
/
Test1.cpp
1
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
class A
{
public:
A(int n = 0) : m_n(n) {
std::cout<<" create " << m_n <<std::endl;
}
A(const A &a) : m_n(a.m_n) {
++m_copy_ctor_calls;
std::cout << "copy " << m_n << " " << m_copy_ctor_calls << std::endl;
}
~A() {
++m_dtor_calls;
std::cout << "delete " << m_n << " " << m_dtor_calls << std::endl;
}
private:
int m_n;
public:
static int m_copy_ctor_calls;
static int m_dtor_calls;
};
int A::m_copy_ctor_calls = 0;
int A::m_dtor_calls = 0;
int main()
{
A *p = nullptr;
{
const A a = 2;
p = new A[4];
p[0] = a;
}
std::cout << A::m_copy_ctor_calls << A::m_dtor_calls << std::endl;
p[1] = A(1);
p[2] = 2;
p[3] = 6;
delete [] p;
std::cout << A::m_copy_ctor_calls << A::m_dtor_calls << std::endl;
std::cout << "Code Completed" << std::endl;
return 0;
}