#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; }
运行结果:
时间: 2024-10-28 11:30:44