home *** CD-ROM | disk | FTP | other *** search
- // \EXAMPLES\EX0808.CPP
- // program that access members of nested classes
-
- //--------------------------------------------------------------
- #include <iostream.h>
-
- //--------------------------------------------------------------
- // global declaration
- int a;
-
- //--------------------------------------------------------------
- //declartion of nested classes Tower and Bell
-
- struct Tower
- { int m;
- static int r;
- class Bell
- { int k;
- public:
- void ring(Tower* t )
- { //m = 85; error - m not accessible
- t->m = 85; // OK - access through pointer
- r = 50; // OK - r is static
- a = 100; } // OK - a is global
- };
- void pull()
- { //k = 75; error - k is private
- cout << "function pull()" << endl;
- }
- };
-
- //--------------------------------------------------------------
- // define and initialize static member
- int Tower::r = 0;
-
- //--------------------------------------------------------------
- //main to exercise Tower and Bell
-
- void main()
- { //Bell chime; error - Bell not in scope
- Tower::Bell chime; // OK
- Tower test;
- test.pull();
- chime.ring(&test);
- cout << a << '\t' << test.m << '\t' << Tower::r << '\t'
- << endl;
- }
-
- //--------------------------------------------------------------
-