7_66.cpp
上传用户:zipjojo
上传日期:2009-07-20
资源大小:70k
文件大小:1k
- #include <iostream.h>
- class cB
- {
- public:
- cB();
- cB(int);
- ~cB();
- int get(){return B_value;}
- protected:
- int B_value;
- };
- class cA
- {
- public:
- cA(int,int);
- ~cA();
- int getcA(){ return b.get();}
- protected:
- int a;
- cB b;
- };
- cB::cB()
- { B_value=1;
- cout<<"construct cB. B_value="<<B_value<<endl;
- }
- cB::cB(int v)
- {
- B_value=v;
- cout<<"construct cB. B_value="<<B_value<<endl;
- }
- cB::~cB()
- { cout<<"destruct cB. B_value="<< B_value<<endl;
- }
- cA::cA(int v1,int v2)
- { a=v1;
- cB b(v2); //调用cB的有参构造函数
- cout<<"construct cA. a="<<a<<endl;
- }
- cA::~cA()
- { cout<<"destruct cA."<<endl;
- }
- void main()
- { cA a(5,10);
- cout<<a.getcA()<<endl;
- }