                                                           ++   934

            18.    

        C++   
   .  ,       
    .     
,         
  ,      
.       
      .  ,  
C++,     .

                        18.1.  

          , ,
  .        
.      .
        ,    
 ( ),      ( 
   ),  (       )  
 ,     .
            
  ,   ,  .
      :  
      , ,  ,
  . ,      
   ,      ,     
     .
      ,  ,     
    .    
        . ,
         
 Open Inventor  C++ (. [WERNECKE94]),    
 ,      . , Open
Inventor     ,  
   SoLight:

   class SoSpotLight : public SoLight { ... }
   class SoPointLight : public SoLight { ... }
   class SoDirectionalLight : public SoLight { ... }

    So   ,     ,  
     (  

                                                             ++   935

     ).   (point light) 
  , ,  ,   . 
 (directional light)   ,    .
 (spotlight)  ,    ,
   .
     Open Inventor        
 OpenGL (. [NEIDER93]).    
,    ,   ,  
  RenderMan (. [UPSTILL90]).    
  ,  ,    
  :

   class RiSpotLight : public SoSpotLight { ... }
   class RiPointLight : public SoPointLight { ... }
   class RiDirectionalLight : public SoDirectionalLight { ... }

       ,    
 RenderMan.     Open Inventor - 
    OpenGL.  ,  
   .
    RenderMan       
(     ,  ,  SCLS),   
.   ,         
      SCLS.   ,  
         SoLight.  
         SCLS,
,        Open Inventor.
       SoLight   Open Inventor   ,  
         SCLS , 
      SdRiSpotLight  SdRiDirectionalLight.  
  , ,   ,   
  SCLS     SCLS-  
 :

   SoLight *plight = next_scene_light();

   if ( RiDirectionalLight *pdilite =
         dynamic_cast<RiDirectionalLight*>( plight ))
      pdilite->scls.cast_shadow_map();
   else
      if ( RiSpotLight *pslite =
            dynamic_cast<RiSpotLight*>( plight ))
         pslite->scls.cast_shadow_map();

      //   



( dynamic_cast        
 (RTTI).     ,  
  .  RTTI     19.)

                                                             ++   936

     ,     SCLS,
           (.
. 18.1).

                     SoNode                                  SCLS
                     SoLight
            SoPointLight SoSpotLight    SoDirectionalLight
             RPointLight RSpotLight     RDirectionalLight

. 18.1.    

   class RiDirectionalLight :
         public SoDirectionalLight, public SCLS { ... };

   class RiSpotLight :
         public SoSpotLight, public SCLS { ... };

   // ...
   SoLight *plight = next_scene_light();
   if ( SCLS *pscls = dynamic_cast<SCLS*>(plight))
     pscls->cast_shadow_map();

     .          Open Inventor,
      ,   SoLight -
  SCLS    cast_shadow_map():

   class SoLight : public SoNode {
   public:
      void cast_shadow_map()
         { if ( _scls ) _scls->cast_shadow_map(); }
         // ...
   protected:
      SCLS *_scls;
   };
   // ...
   plight-> cast_shadow_map();


                                                               ++   937

     ,    ( )
,     /   C++. 
       istream ( ) 
ostream ( ).      :

       (     ,
         ,   
                 ..);
       (      
        ..);
        (      
       ..);
    ,   ,     .

           ios,   istream
 ostream  .
    iostream      .  
          ;    
istream  ostream.  ,       
   ios,     .
      
 ,      .  
iostream   . 18.2.

                                ios
                           istream ostream
                    ifstream iostream ofstream
                              fstream

   . 18.2.    iostream ()

           
  .     .  
   (Douglas Schmidt)    (Steve Vinoski) 
[LIPPMAN96b].
             
 .    , Inside the C++ Object Model,
         .
        . 
     . , , , 

                                                           ++   938

 : -,   .     -
; , -    .      
. ,      , ,    
 18.5,         . 
    ,      .
          ,   
      . ,  
ZooAnimal  ,      ,  
     .
    ,  ,    ,
    ,  , 
  .    Panda   
Bear ()  Endangered ().

                 18.2.  

         
:     ,  :

   class Bear : public ZooAnimal { ... };
   class Panda : public Bear, public Endangered { ... };

             :
public, protected  private.     , 
   ,     .
        ,  
 .       ,  
    ,    
 (          ).
 ,      ,     
,        
 .
           
     (.  17.3). ,   

   Panda ying_yang;

  ying_yang      Bear (   
  ZooAnimal),  Endangered   ,
    Panda,    (. . 18.3).

                            ZooAnimal Endangered
                              Bear
                             Panda

   . 18.3.     Panda

                                                              ++   939

            
. ,  ying_yang   :  Bear (
  Bear    ZooAnimal,    
ZooAnimal),   Endangered      Panda.
    17.4,         
   ,    .  ,  
 Bear          
 ,    :

   //     Bear  
   //   Endangered    ...
   Panda::Panda()
         : Endangered( Endangered::environment, 
                       Endangered::critical )
   { ... }

      Bear    ,   
    Endangered   .
          . 
      : ~Panda(),
~Endangered(), ~Bear(), ~ZooAnimal().
     17.3  ,        
       ( 
    ),        .  
     .    
        .   
        .
         
       ,   
    (.  17.4). ,     Bear 
Endangered  - print(),  

    ying_yang.print( cout );

   ,      -
  .

   Error: ying_yang.print( cout ) -- ambiguous, one of
            Bear::print( ostream& )

                                                          ++   940

   : ying_yang.print( cout ) -- ,  
            Bear::print( ostream& )

            Endangered::print( ostream&, int )
            Endangered::print( ostream&, int )

     ,   -   
     (.  17.3).  print()
   ,      . ( , 
 ,     18.4.)
       ,     
     ,   
 ,    .     
 . , ,      Panda
   ,    ZooAnimal, Bear  Endangered:

   extern void display( const Bear& );
   extern void highlight( const Endangered& );

   Panda ying_yang;

   display( ying_yang ); // 
   highlight( ying_yang ); // 

   extern ostream&
      operator<<( ostream&, const ZooAnimal& );
   cout << ying_yang << endl; // 

         
 . ,  ,  :

   extern void display( const Bear& );
   extern void display( const Endangered& );
   Panda ying_yang;
   display( ying_yang ); // : 

     display()    Panda
   :

   Error: display( ying_yang ) -- ambiguous, one of
             display( const Bear& );
             display( const Endangered& );
  : display( ying_yang ) -- ,  
            display( const Bear& );
            display( const Endangered& );

                                                             ++   941

             
 .     . (
       18.4.)
    ,       
 ,        
 Panda. (     17.2    
 17.5.)

   class Bear : public ZooAnimal {
   public:
      virtual ~Bear();
      virtual ostream& print( ostream& ) const;
      virtual string isA() const;
      // ...
   };

   class Endangered {
   public:
      virtual ~Endangered();
      virtual ostream& print( ostream& ) const;
      virtual void highlight() const;
      // ...
   };

       Panda   print(), 
      cuddle():

   class Panda : public Bear, public Endangered
   {
      public:
         virtual ~Panda();
         virtual ostream& print( ostream& ) const;
         virtual void cuddle();
         // ...
   };

     ,      
Panda,   . 18.1.

    18.1.     Panda

                  

                            Panda::~Panda()
   print(ostream&) const              Panda::print(ostream&)
   isA() const                        Bear::isA()
   highlight() const                  Endangered::highlight()
   cuddle()                           Panda::cuddle()


                                                              ++   942

         Bear  ZooAnimal  
 Panda     ,   ,  
 Panda  Endangered,  :

   Bear *pb = new Panda;

   pb ->print( cout ); 		// : Panda::print(ostream&)
   pb->isA(); 			// : Bear::isA()
   pb->cuddle(); 			// :     Bear
   pb->highlight(); 		// :     Bear
   delete pb; 			// : Panda::~Panda()


   ( ,      Panda    
ZooAnimal,         .)
   ,       Endangered 
  Panda     ,   ,
   Panda  Bear,  :

   Endangered *pe = new Panda;

   pe->print( cout ); // : Panda::print(ostream&)

   // :     Endangered
   pe->cuddle();

   pe->highlight(); // : Endangered::highlight()
   delete pe; // : Panda::~Panda()


          
,     . ,   
           
:

                                                            ++   943

   // ZooAnimal *pz = new Panda;
   delete pz;

   // Bear *pb = new Panda;
   delete pb;
   // Panda *pp = new Panda;
   delete pp;

   // Endangered *pe = new Panda;
   delete pe;


     Panda     .  
      Endangered  Bear,  
   ZooAnimal.
         , 
 ,     ,      (.
 17.6). ,     Panda

   class Panda : public Bear, public Endangered
   { ... };
   Panda yin_yang;

     ling_ling

   Panda ling_ling = yin_yang;

    Bear (,   Bear  
ZooAnimal,      ZooAnimal),  
 Endangered      Panda.    
.

                               18.1

       ? ?

(a) class CADVehicle : public CAD, Vehicle { ... };

(b) class DoublyLinkedList:
     public List, public List { ... };

(c) class iostream:
     private istream, private ostream { ... };

                                 18.2

    ,        :

   class A { ... };
   class B : public A { ... };
   class C : public B { ... };
   class X { ... };
   class Y { ... };
   class Z : public X, public Y { ... };
   class MI : public C, public Z { ... };

         :

   MI mi;

                                  18.3

    ,        :

   class X { ... };
   class A { ... };
   class B : public A { ... };
   class C : private B { ... };
   class D : public X, public C { ... };

   D *pd = new D;

       :

   (a) X *px = pd;     (c) B *pb = pd;
   (b) A *pa = pd;     (d) C *pc = pd;



                                   18.4

     ,      :

                                                               ++   945


   class Base {
   public:
      virtual ~Base();
      virtual ostream& print();
      virtual void debug();
      virtual void readOn();
      virtual void writeOn();
      // ...
   };

   class Derived1 : virtual public Base {
   public:
      virtual ~Derived1();
      virtual void writeOn();
      // ...
   };

   class Derived2 : virtual public Base {
   public:
      virtual ~Derived2();
      virtual void readOn();
      // ...
   };

   class MI : public Derived1, public Derived2 {
   public:
      virtual ~MI();
      virtual ostream& print();
      virtual void debug();
      // ...
   };

   Base *pb = new MI;

            :

   (a) pb->print();    (c) pb->readOn();    (e) pb->log();
   (b) pb->debug();  (d) pb->writeOn();    (f) delete pb;


                                   18.5

         18.4 ,  
     pd1  pd2:

   (a) Derived1 *pd1 new MI;
        Derived2 d2 = obj;

   (b) MI obj;


                                                            ++   946

             18.3. ,    

        .    
   ;     -,
    ,        .
 ,       ߔ, ..
     .  (Bear) 
   (ZooAnimal);  (AudioBook)  ,
  (LibraryLendingMaterial).  ,  Bear   
ZooAnimal,    Panda.  AudioBook   LibBook (
),      LibraryLendingMaterial.    , 
  ,        
,       ( , , 
  ).      
  .
        .  
     ,   
,     .
    ,    ,   PeekbackStack,
        peekback():

   bool   PeekbackStack::peekback( int index, type &value ) { ... }

 value     index,  peekback()  true.  
peekback()  false,    index    
value     .
     PeekbackStack    :

      PeekbackStack:    ;
      :    
      ,      ..

        ,      (
         , 
    , .  6).    
 (,   ,    )
   ,       PeekbackStack.
  ,       .
       IntArray,    2.3 (   
  deque       ,
   int ). ,  ,   ,  
   IntArray    PeekbackStack. 
  . (,     
 IntArray,    ,   .)
   :

                                                              ++   947

   #include "IntArray.h"

   class PeekbackStack : public IntArray {
   private:
      const int static bos = -1;
   public:
      explicit PeekbackStack( int size )
         : IntArray( size ), _top( bos ) {}
      bool empty() const { return _top == bos; }
      bool full() const { return _top == size()-1; }
      int top() const { return _top; }
      int pop() {
         if ( empty() )
            /*   */ ;
            return _ia[ _top-- ];
      }
      void push( int value ) {
         if ( full() )
             /*   */ ;
             _ia[ ++_top ] = value;
      }
      bool peekback( int index, int &value ) const;
   private:
      int _top;
   };

   inline bool PeekbackStack::peekback( int index, int &value ) const
   {
      if ( empty() )
         /*   */ ;
         if ( index < 0 || index > _top )
         {
              value = _ia[ _top ];
              return false;
         }
         value = _ia[ index ];
         return true;
   }

    , ,       PeekbackStack,
      IntArray:

   extern void swap( IntArray&, int, int );
   PeekbackStack is( 1024 );

   //    PeekbackStack
   swap(is, i, j);
   is.sort();
   is[0] = is[512];

                                                                ++   948

    PeekbackStack        
 ,  .    
IntArray     .
     ,       ߔ.
 PeekbackStack     IntArray,    
   .   IntArray    
  PeekbackStack.
           ,
     .    
   .     
 PeekbackStack     - 
  .
       PeekbackStack    public 
    private.      public 
private     :

   class PeekbackStack : private IntArray { ... };


                        18.3.1.   

     PeekbackStack      IntArray
,    ?       ? .
           
ߔ.   PeekbackStack    IntArray  
 Ҕ.  PeekbackStack   IntArray  
 .  Ҕ,  ,   
 ,   .       
 .     IntArray   PeekbackStack. 
 PeekbackStack   :

                                                              ++   949

   class PeekbackStack {
   private:
      const int static bos = -1;
   public:
      explicit PeekbackStack( int size ) :
         stack( size ), _top( bos ) {}
      bool empty() const { return _top == bos; }
      bool full() const { return _top == size()-1; }
      int top() const { return _top; }
      int pop() {
         if ( empty() )
            /*   */ ;
           return stack[ _top-- ];
      }
      void push( int value ) {
         if ( full() )
             /*   */ ;
             stack[ ++_top ] = value;
      }
      bool peekback( int index, int &value ) const;
   private:
      int _top;
      IntArray stack;
   };

   inline bool PeekbackStack::peekback( int index, int &value ) const
   {
      if ( empty() )
         /*   */ ;
         if ( index < 0 || index > _top )
         {
            value = stack[ _top ];
            return false;
         }
      value = stack[ index ];
     return true;
   }


   ,         Ҕ
   ,   
:

        -    , 
        ;
               , 
          (     
      18.3.4);
    ,      PeekbackStack,    
     ,      . 



                                                               ++   950

         ,    
      (  ).

                    18.3.2.   

         PeekbackStack  IntArray,  
    IntArray    PeekbackStack.
     ,    PeekbackStack     
  :

   is.size();

           
 .  ,  ,  - size() 
IntArray:

   class PeekbackStack : private IntArray {
   public:
      //    
      using IntArray::size;
      // ...
   };

            ,  
        
   . ,    
 PeekbackStack,    .   ,
  PeekbackStack,      ia 
_size  IntArray:

   template <class Type>
   class PeekbackStack : private IntArray {
   public:
       using intArray::size;
       // ...
   protected:
      using intArray::size;
      using intArray::ia;
      // ...
   };

           
,             .
        , 
        .
,    Booch Components   
  Queue (.     (Michaeel Vilot)   
(Grady Booch)  [LIPPMAN96b]):

                                                               ++   951

   template < class item, class container >
   class Unbounded_Queue:
      private Simple_List< item >, // 
      public Queue< item > // 


                       18.3.3.  

         .    
        , ..
    ,       
 . ,      PeekbackStack 
Stack,   

   // :      
   // PeekbackStack:   IntArray  
   class Stack : private IntArray { ... }

   ,    IntArray  
Stack     .    
 :

   class PeekbackStack : public Stack { ... };

 Stack   IntArray :

   class Stack : protected IntArray { ... };


                          18.3.4.  

       :

      ,        
     .       PeekbackStack;
      ,         
       .

          
   .  ,     
 .         ?
   ,         Endangered.
       ZooAnimal    
    ?  ,    ZooAnimal
  ,   ,       
 (      ).
        , ,  ,  
  . ( ,   ,    

                                                             ++   952

     ,    
.          
,        , 
  .  , ,   
  .        
; ,   ,    [KOENIG97],  6  7.)
     ,      ZooAnimal 
 ,        (,
            ,
  ).
     Endangered    ,    
,   . (,      .
      .   3.6  
  .)
        ,    ,
     Endangered   .
          
   .  ,    , 
   , , ,      
  .

   class ZooAnimal {
   public:
      // ...
      const Endangered* Endangered() const;
      void addEndangered( Endangered* );
      void removeEndangered();
      // ...
   protected:
      Endangered *_endangered;
      // ...
   };

    ,        , 
   -   
 ,   - .
,    ZooAnimal   UNIX-  , 
   DisplayManager:

   class DisplayManager { ... };
   class DisplayUNIX : public DisplayManager { ... };
   class DisplayPC : public DisplayManager { ... };

     ZooAnimal     DisplayManager, 
    ,   . 
:       ?
          DisplayManager,  
      DisplayUNIX,   DisplayPC.

                                                            ++   953

         DisplayManager   
  .  , -
      ( .
[LIPPMAN96a].)
     ,     ZooAnimal    
 DisplayManager:

           ,    
    ZooAnimal    DisplayManager,    
       ;
        ,   
     DisplayManager        ,
        ,    0;
           ,   
      ,   . 
          
       DisplayManager       .

   , ,     ZooAnimal   
    DisplayManager  .   
     ZooAnimal,   
DisplayManager.

                                18.6

   ,       ,     
:

   (a) Queue : List //  : 
   (b) EncryptedString : String //   : 
   (c) Gif : FileFormat
   (d) Circle : Point //  : 
   (e) Dqueue : Queue, List
   (f) DrawableGeom : Geom, Canvas //   : , 

                                  18.7

     IntArray   PeekbackStack (.  18.3.1)   deque
  .     .

                                  18.8

          ,   
.

                    18.4.     

         ,    
    (.  13.9  13.10).   
       
.          , 
      .

                                                            ++   954

            
        ,    
  .     
,     . ,  
  ZooAnimal:

   class ZooAnimal {
   public:
      ostream &print( ostream& ) const;
      //       
      string is_a;
      int ival;
   private:
      double dval;
   };

     Bear:

   class Bear : public ZooAnimal {
   public:
      ostream &print( ostream& ) const;
      //       
      string name;
      int ival;
   };

    :

   Bear bear;
   bear.is_a;

    :

    bear     Bear.    is_a   
      Bear.   .
      Bear   ZooAnimal,    is_a  
       . ,     .
       .

          ,    ,
      .  ,   ,
     .    ,    
    . ,   :

   bear.ival;

                                                             ++   955

ival     Bear,       
 .
    ,   ,    ,    ,
 .      , 
        :

   bear.ZooAnimal::ival;

       ,   ival    
  ZooAnimal.
          
  (,     -   
):

   int ival;

   int Bear::mumble( int ival )
   {
      return ival + //   
         ::ival + //    
         ZooAnimal::ival +
         Bear::ival;
   }

      ival     .
(   ival     mumble(),    
    Bear.   ival      Bear, 
   ZooAnimal.    ival    ,     
 .)
          ,  
   .   ,   .
,   mumble():

   int dval;
   int Bear::mumble( int ival )
   {
      // :      ZooAnimal::dval
      return ival + dval;
   }

    ,        
   ,     .    
    :

   (a)   dval     -  Bear?
       .
   (b)   dval    Bear? .

                                                             ++   956

   (c)   dval    ZooAnimal? .   
         .

       ,  ,     . 
  : dval   ,      
mumble() .  (, ,   )  
     :

   return ival + ::dval; // 

           ? 
        
,  ,     . , ,
 :

   int dval;
   int Bear::mumble( int ival )
   {
      foo( dval );
      // ...
   }

      foo()  ,    ZooAnimal::dval
          
  mumble(),         .
          -    
,     ,    -: 
         . 
        
:

   ostream& Bear::print( ostream &os) const
   {
      //  ZooAnimal::print(os)
      ZooAnimal::print( os );
      os << name;
      return os;
  }


       18.4.1.      

           
?      , 
     ,      
 .    ,  
        . ,
   :

                                                                ++   957

   class Endangered {
   public:
      ostream& print( ostream& ) const;
      void highlight();
      // ...
   };

   class ZooAnimal {
   public:
      bool onExhibit() const;
      // ...
   private:
      bool highlight( int zoo_location );
      // ...
   };

   class Bear : public ZooAnimal {
   public:
      ostream& print( ostream& ) const;
      void dance( dance_type ) const;
      // ...
   };

   Panda     :

   class Panda : public Bear, public Endangered {
   public:
      void cuddle() const;
      // ...
   }; 

       print()  highlight()    
Bear  Endangered   ,    
          .
           print()  
 ,     highlight()  ( 
  ):         . 
,   Endangered      ,  
ZooAnimal   ,       .
         (,    ,  ,  
  ). Bear   -
highlight()  ZooAnimal;   ,     Bear  Panda
. , Panda        highlight,
         
.
         ,   .
,  

                                                             ++   958

   int main()
   {
      Panda yin_yang;
      yin_yang.dance( Bear::macarena );
   }

     Panda,    yin_yang.
   :

   void Panda::mumble()
   {
      dance( Bear::macarena );
      // ...
   }

      - mumble(). 
 dance   ,       .
         .
          
        Endangered  
Bear/ZooAnimal.         
,     , , ,   
dance():

   // : Bear::dance()
   yin_yang.dance( Bear::macarena );

           ,   
      .   
   print():

   int main()
   {
      // : :  
      //       Bear::print( ostream& ) const
      //       Endangered::print( ostream& ) const

      Panda yin_yang;
      yin_yang.print( cout );
   }

            
   -     
:

                                                          ++   959
   int main()
   {
      // ,    
      Panda yin_yang;
      yin_yang.Bear::print( cout );
   }

     :    , 
   Panda;  ,    
      Panda    ,
   .      
       ,   
 :

   inline void Panda::highlight() {
      Endangered::highlight();
   }

   inline ostream&
   Panda::print( ostream &os ) const
   {
      Bear::print( os );
      Endangered::print( os );
      return os;
  }

       ,  
,     ,   
   -,   .

                                     18.9

      :

                                                           ++   960

   class Base1 {
   public:
      // ...
   protected:
      int ival;
      double dval;
      char cval;
      // ...
   private:
      int *id;
      // ...
   };

   class Base2 {
   public:
      // ...
   protected:
      float fval;
      // ...
   private:
      double dval;
      // ...
   };

   class Derived : public Base1 {
   public:
         // ...
   protected:
      string sval;
      double dval;
      // ...
   };

   class MI : public Derived, public Base2 {
   public:
      // ...
   protected:
      int *ival;
      complex<double> cval;
      // ...
   };

  - MI::foo():

   int ival;
   double dval;

   void MI::
   foo( double dval )
   {
      int id;
      // ...
   }

   (a)      MI?     ,   
        ?
   (b)     MI::foo()?

                                                              ++   961

                                  18.10

        18.9, ,   
   - MI::bar():

   void MI::bar()
   {
      int sval;
      //     ,     ...
   }

   (a) dval = 3.14159; (d) fval = 0;
   (b) cval = 'a'; (e) sval = *ival;
   (c) id = 1;

                                  18.11

        18.9   - MI::foobar():

   int id;

   void MI::
   foobar( float cval )
   {
      int dval;
      //     ,     ...
   }

   (a)    dval    dval  Base1 
        dval  Derived.
   (b)     cval  MI  fval  Base2.
   (c)    cval  Base1    sval 
       Derived.

                                   18.12

      ,    - print():

                                                             ++   962

   class Base {
   public:
      void print( string ) const;
      // ...
   };

   class Derived1 : public Base {
   public:
      void print( int ) const;
      // ...
   };

   class Derived2 : public Base {
   public:
      void print( double ) const;
      // ...
   };

   class MI : public Derived1, public Derived2 {
   public:
      void print( complex<double> ) const;
      // ...
   };

   (a)      ?

   MI mi;
   string dancer( "Nejinsky" );
   mi.print( dancer );

   (b)    MI,      
       ?


                          18.5.   A

       C++     
.   :

   class Bear : public ZooAnimal { ... };

  Bear    -  
  ZooAnimal,    ,    Bear.
   ,       - :

   class PolarBear : public Bear { ... };

   PolarBear    ,  
PolarBear, Bear  ZooAnimal.
           , 
 ,     
.      , 
       . 

                                                             ++   963

         iostream. 
   . 18.2: istream  ostream     
  ios,  iostream     istream,   
ostream.

   class iostream : public istream, public ostream { ... };

       iostream    ios:  istream  
ostream.   ?       
 ios    ,   iostream   
.  ,     .  
  ,      .
,       ios  
.     ?  ,   istream 
ostream    ios -?   ,
   iostream     ios?  
        .
          
  :  .     
    ,   ,   
    .    
  .     
      ,  
  .
            
Panda.          
    ,     :   
 .      , 
,   ,      
Panda   :

   class Panda : public Bear, public Raccoon, public Endangered { ... };

       Panda   . 18.4:  
     Bear  Raccoon  ZooAnimal, 
     Panda  Bear, Raccoon ,  
,   Endangered   18.2.

   ZooAnimal                                               Endangered

                   Bear            Raccoon


                                                                 ++   964

                                                  Panda

    ..>  
    - - - ->  

   . 18.4.     Panda

           :
 (     Bear  Raccoon)   
 ,      . 
       Panda,  
    Bear  Raccoon     , 
  Panda  .
            ,  -
      ? ,  
:      
   (. [LIPPMAN96a],    
  ).
       ?    
, ,   iostream     Panda,
     ,  
.
           , 
      .  ,  -
   .

                  18.5.1.    

           
 virtual. ,    ZooAnimal  
  Bear  Raccoon:

  //     public  virtual
   // 
   class Bear : public virtual ZooAnimal { ... };
   class Raccoon : virtual public ZooAnimal { ... };

           , 
     .    , 
      .  ,  
     ,   ,
      
       .    
          
,    . ,   

                                                             ++   965

   Panda  ,  Panda 
 :

   extern void dance( const Bear* );
   extern void rummage( const Raccoon* );

   extern ostream&
      operator<<( ostream&, const ZooAnimal& );

   int main()
   {
      Panda yin_yang;

      dance( &yin_yang ); // 
      rummage( &yin_yang ); // 
      cout << yin_yang; // 
      // ...
   }

    ,      ,  
,        ,   
.    ZooAnimal:

   #include <iostream>
   #include <string>

   class ZooAnimal;
   extern ostream& operator<<( ostream&, const ZooAnimal& );

   class ZooAnimal {
   public:
      ZooAnimal( string name, bool onExhibit, string fam_name )
         : _name( name ), _onExhibit( onExhibit ), _fam_name( fam_name )
      {}

      virtual ~ZooAnimal();
      virtual ostream& print( ostream& ) const;
      string name() const { return _name; }
      string family_name() const { return _fam_name; }
      // ...

   protected:
      bool _onExhibit;
      string _name;
      string _fam_name;
      // ...
   };

           
     virtual. , ,
   Bear:

                                                              ++   966

   class Bear : public virtual ZooAnimal {
   public:
      enum DanceType {
         two_left_feet, macarena, fandango, waltz };

      Bear( string name, bool onExhibit=true )
          : ZooAnimal( name, onExhibit, "Bear" ),
            _dance( two_left_feet )
      {}

      virtual ostream& print( ostream& ) const;
      void dance( DanceType );
      // ...

   protected:
      DanceType _dance;
      // ...
   };

    Raccoon:

   class Raccoon : public virtual ZooAnimal {
   public:
      Raccoon( string name, bool onExhibit=true )
         : ZooAnimal( name, onExhibit, "Raccoon" ), _pettable( false )
      {}

      virtual ostream& print( ostream& ) const;

      bool pettable() const { return _pettable; }
      void pettable( bool petval ) { _pettable = petval; }
      // ...
   protected:
      bool _pettable;
      // ...
   };


                        18.5.2.   

   ,        
,    .    
 Bear  Raccoon   .   ,  
    Panda?

                                                             ++   967

   class Panda : public Bear, public Raccoon, public Endangered {
   public:
      Panda( string name, bool onExhibit=true );
      virtual ostream& print( ostream& ) const;

      bool sleeping() const { return _sleeping; }
      void sleeping( bool newval ) { _sleeping = newval; }
      // ...
   protected:
      bool _sleeping;
      // ...
   };

     ,     Bear  Raccoon 
 ZooAnimal    .  ,   
     fam_name ( )  
,      Panda.
          
      (.  17.4). ,
 Panda,   ZooAnimal,    
 ZooAnimal     .   
  Panda      
  ZooAnimal.
          
 . ,     Bear:

   Bear winnie( "pooh" );

 Bear       winnie, 
   ZooAnimal,    Bear.  
:

   cout << winnie.family_name();

  :

   The family name for pooh is Bear
   (   pooh   Bear)
   
  

   Raccoon meeko( "meeko" );

Raccoon        meeko,  
  ZooAnimal,    Raccoon.   :

   cout << meeko.family_name();


                                                                  ++   968

 :

   The family name for meeko is Raccoon
   (   meeko -  Raccoon)

        Panda:

   Panda yolo( "yolo" );

      yolo  Panda,   
   ZooAnimal.
   Panda,     ZooAnimal 
  Raccoon  Bear  ,     
,        Panda.  
 :

   Panda::Panda( string name, bool onExhibit=true )
      : ZooAnimal( name, onExhibit, "Panda" ),
         Bear( name, onExhibit ),
         Raccoon( name, onExhibit ),
         Endangered( Endangered::environment,
                            Endangered::critical ),
         sleeping( false )
   {}

      Panda    ZooAnimal   , 
  ZooAnimal   ,   , 
     Panda.
     :

   cout << yolo.family_name();

 :

   The family name for yolo is Panda

(   yolo -  Panda)
     Panda  Raccoon  Bear  ,  
 .       
     .   
Panda       ,    Panda  
      ZooAnimal    .
    ,   ,   Bear  Raccoon,
   ,       
.     ,    
, ,     .
   Bear:

                                                           ++   969

   class Bear : public virtual ZooAnimal {
   public:
      //       
      Bear( string name, bool onExhibit=true )
         : ZooAnimal( name, onExhibit, "Bear" ),
            _dance( two_left_feet )
     {}

      // ...   

   protected:
      //       
      Bear() : _dance( two_left_feet ) {}
      // ...   
   };

       ,     
 .        
 Raccoon,      Panda:

   Panda::Panda( string name, bool onExhibit=true )
      : ZooAnimal( name, onExhibit, "Panda" ),
         Endangered( Endangered::environment,
                             Endangered::critical ),
          sleeping( false )
   {}


                 18.5.3.     

         , 
      . ,  
   TeddyBear ( )    :
  ToyAnimal ( )   ZooAnimal, 
   Bear:

   class Character { ... };          // 
   class BookCharacter : public Character { ... };
                                            //  
   class ToyAnimal { ... }; // 

   class TeddyBear : public BookCharacter,
      public Bear, public virtual ToyAnimal
   {};

       . 18.5,    
 ,    .

              Character                          ZooAnimal                    ToyAnimal

                                                           ++   970

      BookCharacter        Bear
                  TeddyBear

   ..>  
   - - - -> e 

   . 18.5.     TeddyBear

            
  .      
 BookCharacter,  Bear   ToyAnimal.  
  , ..        . ,
  BookCharacter   Character,  
BookCharacter.   Bear  ZooAnimal,   Bear.
           
  TeddyBear : ZooAnimal,  ToyAnimal.
           ,  
 ,     :
BookCharacter,  Bear.    BookCharacter
     Character.
     :

   TeddyBear Paddington;

       :

   ZooAnimal(); 		//    Bear
   ToyAnimal(); 		//    
   Character(); 		//    BookCharacter
   BookCharacter(); 	//    
   Bear();		//    
   TeddyBear(); //   

   ZooAnimal  ToyAnimal  TeddyBear  
   Paddington.
          (
     )  .
,     ,  
.

                                                          ++   971


                 18.5.4.     

      Bear ,      -
onExhibit(),   ZooAnimal:

   bool Bear::onExhibit() { ... }

      onExhibit()   Bear    ,
   :

   Bear winnie( " " );

      onExhibit()   Raccoon    -
,   ZooAnimal:

   Raccoon meeko( "  " );
   meeko.onExhibit(); // ZooAnimal::onExhibit()

     Panda     .    
   :

       ZooAnimal, ,  name()  family(), 
       Bear,   Raccoon;
    onExhibit()    ZooAnimal,  
      Raccoon    Bear;
      Bear  Raccoon   print() 
    ZooAnimal.

    ,   ,    
     Panda?     
:      .   
,           
. ,    Panda:

   Panda spot( "Spottie" );

    

   spot.name();

  - name()   ZooAnimal, 


   spot.onExhibit();

 - onExhibit()   Bear.

                                                             ++   972

            (  
  -,    -,     )  
         ,  
,      (
).       ,   
    ,     :
       
       ( ). 
      ,   
.     ,  
    ( ).
   ,      
onExhibit()   Panda :

   // :    
   Panda yolo( " " );
   yolo.onExhibit();

            
 ,      
 -  (.  18.4.1).
      ,    
,   ,      ,  
. ,   Bear  onExhibit() 
    ZooAnimal,   Raccoon:

   // :     
   //  Bear::onExhibit()
   yolo.onExhibit();

                
  ,        .
,   Raccoon    onExhibit(),     
 Panda        
:

   bool Panda::onExhibit()
   {
      return Bear::onExhibit() &&
               Raccoon::onExhibit() &&
               ! _sleeping;
   }

                                    18.13

     :

                                                            ++   973

   class Final : public MI, public Class { ... };
   class Class { ... };
   class Base : public Class { ... };
   class Derived1 : virtual public Base { ... };
   class Derived2 : virtual public Base { ... };
   class MI : public Derived1,
                  public Derived2 { ... };
   class Final : public MI, public Class { ... };

   (a)          
       Final?
   (b)    Base   Final?   
       Class?

   (c)       ?

   Base *pb;
   MI *pmi;
   Class *pc;
   Derived2 *pd2;

   (i) pb = new Class; (iii) pmi = pb;
   (ii) pc = new Final; (iv) pd2 = pmi;

                                       18.14

     :

                                                            ++   974

   class Base {
   public:
      bar( int );
      // ...
   protected:
      int ival;
      // ...
   };

   class Derived1 : virtual public Base {
   public:
      bar( char );
      foo( char );
      // ...
   protected:
      char cval;
      // ...
   };

   class Derived2 : virtual public Base {
   public:
      foo( int );
      // ...
   protected:
      int ival;
      char cval;
      // ...
   };

   class VMI : public Derived1, public Derived2 {};

            VMI,  
?    ?

                                             18.15

     Base   : 

   class Base {
   public:
      Base();
      Base( string );
      Base( const Base& );
      // ...
   protected:
      string _name;
   };

          :

   (a)  
        class Derived1 : virtual public Vase { ... };
        class Derived2 : virtual public Vase { ... };
   (b) class VMI : public Derived1, public Derived2 { ... };
   (c) class Final : public VMI { ... };

                                                             ++   975

              18.6.     A

         
,     Array (.  2.4)  
 Array (.  16),  ,    
 .      ,   
    .
         
:

   class IntStack : private Array<int> {};

           :

   class Base {};
   template <class Type>
      class Derived : public Base {};

            :

   template <class Type>
   class Array_RC : public virtual Array<Type> {};

        int  Array  
     IntStack.      Base
    ,    Derived. 
      Array_RC  
  ,    Array. , 

   Array_RC<int> ia;

   Array  Array_RC.
    ,  -     [MURRAY93]:

   template < typename Type >
   class Persistent : public Type { ... };

         (persistent)   
 .    (Murray),  Type  
:     . , 

   Persistent< int > pi; // 

                                                           ++   976

   ,       
.
   ,     ,   
 .   :

   template <class T> class Base {};

  :

   template < class Type >
   class Derived : public Base<Type> {};

     :

   // : Base -  ,
   //       
   template < class Type >
   class Derived : public Base {};
 
       Array,    16,   
     Array,    
;    Array;   Array,  
  .     
Array    :

          ,  
    ;
         -,    , 
     .

     ,      ? . 
     ,    .  
  Array      
. , ,      (
-     ):

                                                              ++   977

  ,      ,   , 
          
     . ,   ,
      ,      :


                                                               ++   978

   #ifndef ARRAY_H
   #define ARRAY_H

   #include <iostream>

   //     operator<<
   template <class Type> class Array;

   template <class Type> ostream& operator<<( ostream &, Array<Type> & );

   template <class Type>
   class Array {
      static const int ArraySize = 12;
   public:
      explicit Array( int sz = ArraySize ) { init( 0, sz ); }
      Array( const Type *ar, int sz ) { init( ar, sz ); }
      Array( const Array &iA ) { init( iA.ia, iA.size()); }
      virtual ~Array() { delete[] ia; }

      Array& operator=( const Array & );
      int size() const { return _size; }
      virtual void grow();

      virtual void print( ostream& = cout );

      Type at( int ix ) const { return ia[ ix ]; }
      virtual Type& operator[]( int ix ) { return ia[ix]; }

      virtual void sort( int,int );
      virtual int find( Type );
      virtual Type min();
      virtual Type max();
   protected:
      void swap( int, int );
      void init( const Type*, int );
      int _size;
      Type *ia;
   };
#endif

     ,      ,   , 
          
     . ,   ,
      ,      :

   int find( const Array< int > &ia, int value )
   {
      for ( int ix = 0; ix < ia.size(); ++ix )
         //     
         if ( ia[ ix ] == value )
            return ix;
      return -1;
}

                                                                ++   978

         -
at(),   .

          18.6.1.  ,    
                            

     try_array()   16.13,    
    Array,   :

   int index = iA.find( find_val );
   Type value = iA[ index ];

find()      find_val  -1,  
   .   ,     ,   
 -1.  -1    ,   
value    .     Array,  
    ,  Array_RC     
  Array_RC.h:

   #ifndef ARRAY_RC_H
   #define ARRAY_RC_H

   #include "Array.h"

   template <class Type>
   class Array_RC : public virtual Array<Type> {
   public:
       Array_RC( int sz = ArraySize )
         : Array<Type>( sz ) {}
      Array_RC( const Array_RC& r );
      Array_RC( const Type *ar, int sz );
      Type& operator[]( int ix );
   };
  #endif

            
      :

   Array_RC( int sz = ArraySize )
      : Array<Type>( sz ) {}

     :

   // : Array -    
   Array_RC( int sz = ArraySize ) : Array( sz ) {}

                                                           ++   979

       Array_RC     , 
       .   
        Array.
, ,    ,   Array_RC 
    .    Array_RC 
  Array,    
.
      - Array_RC,    Array_RC.C
(   Array     Array.C, 
      ,   
16.18):

   #include "Array_RC.h"
   #include "Array.C"
   #include <assert.h>

   template <class Type>
   Array_RC<Type>::Array_RC( const Array_RC<Type> &r )
      : Array<Type>( r ) {}

   template <class Type>
   Array_RC<Type>::Array_RC( const Type *ar, int sz )
      : Array<Type>( ar, sz ) {}

   template <class Type>
   Type &Array_RC<Type>::operator[]( int ix ) {
      assert( ix >= 0 && ix < Array<Type>::_size );
      return ia[ ix ];
   }

          Array,   _size,
   Array    :

   Array<Type>::_size;

     ,     .  ,  
 Array_RC  ,    ( 
,     ).    
_size,      ,      
   .    _size    ,
     Array<Type>.    
   _size    . ( 
 Array_Sort       .)
     Array_RC    Array. :

   Array_RC<string> sa;

  string   Array_RC,    Array.
    try_array() ( .   16.13),
    Array_RC.    ,   
   :

                                                          ++   980

   #include "Array_RC.C"
   #include "try_array.C"

   int main()
   {
      static int ia[] = { 12,7,14,9,128,17,6,3,27,5 };

      cout << "   Array_RC<int>\n";
      try_array( iA );

      return 0;
   }

         :

      Array_RC<int>

   try_array:   
   ( 10 )< 12, 7, 14, 9, 128, 17
            6, 3, 27, 5 >

   try_array:  
   ( 10 )< 128, 7, 14, 9, 128, 128
           6, 3, 27, 3 >

   try_array:  
   ( 10 )< 12, 7, 14, 9, 128, 128
           6, 3, 27, 3 >

   try_array:   
   ( 10 )< 12, 7, 128, 9, 128, 128
           6, 3, 27, 3 >

   try_array:   grow
   ( 10 )< 12, 7, 128, 9, 128, 128
           6, 3, 27, 3, 0, 0
           0, 0, 0, 0 >

    : 5  : -1
   Assertion failed: ix >= 0 && ix < _size


               18.6.2.    

       Array    Array_Sort. 
      Array_S.h:

                                                             ++   981

   #ifndef ARRAY_S_H_
   #define ARRAY_S_H_

   #include "Array.h"

   template <class Type>
   class Array_Sort : public virtual Array<Type> {
   protected:
      void set_bit() { dirty_bit = true; }
      void clear_bit() { dirty_bit = false; }

      void check_bit() {
         if ( dirty_bit ) {
             sort( 0, Array<Type>::_size-1 );
             clear_bit();
         }
      }
   public:
      Array_Sort( const Array_Sort& );
      Array_Sort( int sz = Array<Type>::ArraySize )
        : Array<Type>( sz )
      { clear_bit(); }

      Array_Sort( const Type* arr, int sz )
         : Array<Type>( arr, sz )
      { sort( 0,Array<Type>::_size-1 ); clear_bit(); }

      Type& operator[]( int ix )
      { set_bit(); return ia[ ix ]; }

      void print( ostream& os = cout ) const
      { check_bit(); Array<Type>::print( os ); }
      Type min() { check_bit(); return ia[ 0 ]; }
      Type max() { check_bit(); return ia[ Array<Type>::_size-1 ]; }

      bool is_dirty() const { return dirty_bit; }
      int find( Type );
      void grow();
   protected:
      bool dirty_bit;
   };
   #endif

   Array_Sort     dirty_bit.     true, 
 ,   - .   
  : is_dirty()   dirty_bit;
set_bit()  dirty_bit  true; clear_bit()  dirty_bit 
false; check_bit()  ,  dirty_bit  true,  
   false.  ,      
 ,  set_bit().
        Array    
.

   Array<Type>::print( os );

                                                              ++   982

 - print()   Array, 
  Array_Sort. :

   Array_Sort<string> sas;

  string  : Array_Sort  Array.

   cout << sas;

     Array,   string,
     sas.    

   ar.print( os );

     print()  Array_Sort,
  string.   check_bit(),  
  - print()  Array,  
 . (,        
           .) 
         ,
 ar.   ,     
    ,   Array::print(). 
   ,      
         ,  
print()   Array_Sort (.  17.5).
   -,    ,    Array_S.C.
     -  . ,  
  ,   ,     :

   template <class Type>
   Array_Sort<Type>::
   Array_Sort( const Array_Sort<Type> &as )
      : Array<Type>( as )
   {
      // : as.check_bit()  !
      // ----  .  ...
      if ( as.is_dirty() )
         sort( 0, Array<Type>::_size-1 );
      clear_bit();
   }

            
   .  :

   template <class Type>
   Array_Sort<Type>::Array_Sort( const Array_Sort<Type> &as )

    

                                                             ++   983
   template <class Type>
   Array_Sort<Type>::Array_Sort<Type>( // :    

   Array_Sort    ,  
 .

  ,     :

   if ( as.is_dirty() )
      sort( 0, _size );

  

   as.check_bit();

       : check_bit()    -,
   .      
 .  check_bit()   as  
      .
    :    ,  
as,   ,  ,      
Array_Sort  . , ,   dirty_bit    
.      Array_Sort
   ia  _size,    Array. 
    clear_bit()   
  ,  sort(),    .
 Array_Sort      -:

   //  
   template <class Type>
   Array_Sort<Type>::Array_Sort( const Array_Sort<Type> &as )
      : Array<Type>( as )
   {
      dirty_bit = as.dirty_bit;
      clear_bit();
  }

      - grow().1     ,
      Array   
 ,       dirty_bit:

  1       , 
       -    
    ,  grow()      . .  
      [LIPPMAN96b].

                                                             ++   984

   template <class Type>
   void Array_Sort<Type>::grow()
   {
      Array<Type>::grow();
      sort( 0, Array<Type>::_size-1 );
      clear_bit();
   }

      - find()  Array_Sort:

   template <class Type>
   int Array_Sort<Type>::find( const Type &val )
   {
      int low = 0;
      int high = Array<Type>::_size-1;
      check_bit();
     while ( low <= high ) {
         int mid = ( low + high )/2;

         if ( val == ia[ mid ] )
            return mid;

         if ( val < ia[ mid ] )
            high = mid-1;
         else low = mid+1;
      }
      return -1;
   }

       Array_Sort    try_array().
         
int  string:

                                                              ++   985

   #include "Array_S.C"
   #include "try_array.C"
   #include <string>

   main()
   {
      static int ia[ 10 ] = { 12,7,14,9,128,17,6,3,27,5 };
      static string sa[ 7 ] = {
         "Eeyore", "Pooh", "Tigger",
         "Piglet", "Owl", "Gopher", "Heffalump"
      };

     Array_Sort<int> iA( ia,10 );
     Array_Sort<string> SA( sa,7 );

      cout << "  Array_Sort<int>"
             << endl;
      try_array( iA );

      cout << "  Array_Sort<string>"
             << endl;
       try_array( SA );

      return 0;
   }

      string      
  ( ,       -1
 ):

     Array_Sort<string>

   try_array:   
   ( 7 )< Eeyore, Gopher, Heffalump, Owl, Piglet, Pooh
          Tigger >

   try_array:  
   ( 7 )< Eeyore, Gopher, Owl, Piglet, Pooh, Pooh
          Pooh >

   try_array:  
   ( 7 )< Eeyore, Gopher, Owl, Piglet, Pooh, Pooh
          Pooh >

   try_array:   
   ( 7 )< Eeyore, Piglet, Owl, Piglet, Pooh, Pooh
          Pooh >

   try_array:   grow
   ( 7 )< <empty>, <empty>, <empty>, <empty>, Eeyore, Owl
           Piglet, Piglet, Pooh, Pooh, Pooh >

    : Tigger  : -1
   Memory fault (coredump)

        ,   
  ,      .     
17.5,           ,  
 ,     .   sort()
      Array. (,   
    .)

                                                               ++   986

               18.6.3.     

          .   
    Array_RC  Array_Sort.   
  (  ,      
  ).     
Array_RC_S.h:

   #ifndef ARRAY_RC_S_H
   #define ARRAY_RC_S_H

   #include "Array_S.C"
   #include "Array_RC.C"

   template <class Type>
   class Array_RC_S : public Array_RC<Type>,
                                 public Array_Sort<Type>
   {
   public:
      Array_RC_S( int sz = Array<Type>::ArraySize )
         : Array<Type>( sz )
      { clear_bit(); }

      Array_RC_S( const Array_RC_S &rca )
         : Array<Type>( rca )
      { sort( 0,Array<Type>::_size-1 ); clear_bit(); }

      Array_RC_S( const Type* arr, int sz )
         : Array<Type>( arr, sz )
      { sort( 0,Array<Type>::_size-1 ); clear_bit(); }

      Type& operator[]( int index )
      {
         set_bit();
         return Array_RC<Type>::operator[]( index );
      }
   };
   #endif

           Array: 
Array_Sort      Array  Array_RC ( 
  ,       
 ).     find()  
   ,    ,  
     .     
Array_Sort       ,
      Array_RC (.  18.5.4).
 ,      find()
   ,    Array_Sort.
         Array_RC  Array_Sort,  
   .   Array_RC_S
      . 
Array_RC_S    ,   
        .  

                                                          ++   987

    Array_RC_S?      
  true   dirty_bit.     
          . 
       .   
   Array_RC   .  

   return Array_RC<Type>::operator[]( index );

  ,     .  
 ,          
.
          try_array(),  
  ,    Array_RC_S  int  string:
 
   #include "Array_RC_S.h"
   #include "try_array.C"
   #include <string>

   int main()
   {
      static int ia[ 10 ] = { 12,7,14,9,128,17,6,3,27,5 };
      static string sa[ 7 ] = {
         "Eeyore", "Pooh", "Tigger",
         "Piglet", "Owl", "Gopher", "Heffalump"
      };

      Array_RC_S<int> iA( ia,10 );
      Array_RC_S<string> SA( sa,7 );

      cout << "  Array_RC_S<int>"
             << endl;
      try_array( iA );

      cout << "  Array_RC_S<string>"
             << endl;
      try_array( SA );

      return 0;
   }

        ,   string (
     ):
  Array_Sort<string>

   try_array:   
   ( 7 )< Eeyore, Gopher, Heffalump, Owl, Piglet, Pooh
          Tigger >

   try_array:  
   ( 7 )< Eeyore, Gopher, Owl, Piglet, Pooh, Pooh
          Pooh >

   try_array:  
   ( 7 )< Eeyore, Gopher, Owl, Piglet, Pooh, Pooh
          Pooh >

   try_array:   
   ( 7 )< Eeyore, Piglet, Owl, Piglet, Pooh, Pooh
          Pooh >

                                                               ++   988

  try_array:   grow
   ( 7 )< <empty>, <empty>, <empty>, <empty>, Eeyore, Owl
   Piglet, Piglet, Pooh, Pooh, Pooh >

    : Tigger  : -1
   Assertion failed: ix >= 0 && ix < size

          Array 
    .  
    [NACKMAN94]. ,  ,  
vector   .

                              18.16

     Array - spy().   ,  
 :    ;    ; 
    find()     .  
 .    Array ,  spy()  
    .

                              18.17

      map ()   
,      .  
,          
Array? ?

                               18.18

     Array,     
    .
