学好C++

A():1
B()1

View Code
 1 #include <iostream>
 2 
 3 using namespace std;
 4 class A
 5 {
 6 protected:
 7     static int count ;
 8     int num ;
 9 public:
10     A()
11     {
12         count++;
13         num = count;
14         cout<<"A():"<<num<<endl;
15     }
16     virtual ~A()
17     {
18         cout<<"~A():"<<num<<endl;
19     }
20 };
21 int A::count =0;
22 
23 class B :public A
24 {
25 public :
26     B()
27     {
28         cout<<"B()"<<num<<endl;
29     }
30     ~B()
31     {
32         cout<<"~B()"<<num<<endl;
33     }
34 };
35 int main()
36 {
37     A * p = new B[2];
38     delete []p;
39     return 0;
40 }
原文地址:https://www.cnblogs.com/fengyehe/p/3051523.html