CHAPTER1-23.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER1-23.cpp
- #include <iostream.h>
- class B1
- {
- public:
- B1(int i)
- { b1 = i; cout<<"构造函数 B1."<<i<<endl; }
- void print() { cout<<b1<<endl; }
- private:
- int b1;
- };
- class B2
- {
- public:
- B2(int i)
- { b2 = i; cout<<"构造函数 B2."<<i<<endl; }
- void print() { cout<<b2<<endl; }
- private:
- int b2;
- };
- class B3
- {
- public:
- B3(int i)
- { b3 = i; cout<<"构造函数 B3."<<i<<endl; }
- int getb3() { return b3; }
- private:
- int b3;
- };
- class A : public B2, public B1
- {
- public:
- A(int i, int j, int k, int l):B1(i), B2(j), bb(k) { a = l; cout<<"构造函数 A."<<l<<endl; }
- void print()
- { B1::print(); B2::print(); cout<<a<<","<<bb.getb3()<<endl; }
- private:
- int a;
- B3 bb;
- };
- void main()
- {
- A aa(1, 2, 3, 4);
- aa.print();
- }