#include<iostream> using namespace std; class G { public: static int m; G( ) //构造函数 { m++; cout<<"G begins\n"; } ~G( ) { cout<<"G ends\n"; m--; } }; int G::m=0; class D:public G { public: D( ) //构造函数 { m++; cout<<"D begins\n"; } ~D( ) { cout<<"D ends\n" ; m-- ; } }; int main( ) { D objg; cout<<G::m<<endl; return 0; }
运行结果:
原文地址:http://blog.csdn.net/ljd939952281/article/details/45767539