                                                               ++   431

                                         9

                             9.  

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

                     9.1.   

   ,  ,      ,
        C++.   
  ,     
 .
        . , 
 

   1 + 3

   ,    

   1.0 + 3.0

    .     
   .   , 
     .   
   ,   ,  
,    .
       ,     .

                 9.1.1.     

          ,    
,      ,     .
,     ,   
  .     ,   
    . ,   max() 
   :

++   432

int i_max( int, int );
int vi_max( const vector<int> & );
int matrix_max( const matrix & );

          :     . 
  ,       ,  
     .
         : 
,        ,   
  (, ,   ..).    
  ,      -
   .      
.
    ,     :

vector<int> vec;
//...
int ix = max( j, k );
int iy = max( vec );

          .

9.1.2.    

    C++              ,  
     ,   .  
     max():

int max ( int, int );
int max( const vector<int> & );
int max( const matrix & );

          
max()    .
             , 
 ( )    :

           
    ,    :

    //  
    void print( const string & );
   void print( vector<int> & );

                                                            ++   433

            
     ,     :

   //      
   void print( const string &str );
   void print( const string & );

           ;
     ,    
,      (  ) 
   :

unsigned int max( int i1, int i2 );
int max( int i1, int i2 ); // :   
//  

           ;

           
      ,     :

    //      
    int max ( int *ia, int sz );
    int max ( int *ia, int = 10 );

     typedef       ,
     .      
  ,     typedef,    ,  
typedef  ,    , , , 
    calc().      
 ,      
:

   // typedef    
   typedef double DOLLAR;
   // :   ,   
   //  
   extern DOLLAR calc( DOLLAR );
   extern int calc( double );

    const  volatile      
. ,     :

++   434

//      
void f( int );
void f( const int );

    const     :  ,  
     .  , 
 ,        
:     . (  , 
   ,    7.3.)  
const  ,   ,     .
,   f(int),       int,
    f(const int).        
  ,     
. f()   

   void f( int i ) { }

 

   void f( const int i ) { }

           ,      
  .
   ,   const  volatile    
  ,      .

//   
void f( int* );
void f( const int* );
//     
void f( int& );
void f( const int& );

9.1.3.      

          ? , , 
      .  
.          . 
 ,      :

void setDate( Date&, int, int, int );
Date &convertDate( const string & );
void printDate( const Date& );

            Date,  
  .     ,  

++   435

  ,     
          
    . ,   C++  
 .        Date, 
    ,   :

#include <string>
class Date {
public:
set( int, int, int );
Date& convert( const string & );
void print();
// ...
};

      .   - Screen 
    ,    
.  ,        
move():

Screen& moveHome();
Screen& moveAbs( int, int );
Screen& moveRel( int, int, char *direction );
Screen& moveX( int );
Screen& moveY( int );

   ,     ,      
.    ,     :

// ,  moveX()  moveY()
Screen& move( int, char xy );

         ,      
 move().     :    , 
    . ,   
   . , moveHome() 
       .    
       ?

//   ?
myScreen.home(); //  ,  !
myScreen.move();

           ,    :
       
   . ,   

++   436

   moveAbs(int, int);
   moveAbs(int, int, char*);

     char*.      
       ,   
  .         
   0:

move( int, int, char* = 0 );

         ,    
.        
 ,   .

9.1.4.     A

             . 
,     ,    :

#include <string>
void print( const string & );
void print( double ); //  print()
void fooBar( int ival )
{
//   :    print()
extern void print( int );
// : print( const string & )     
print( "Value: ");
print( ival ); // : print( int ) 
}

         , ,
    ,    . (-
    13.    - 
   15.)
          .    
    ,   ,   
,    . :

#include <string>
namespace IBM {
extern void print( const string & );
extern void print( double ); //  print()
}
namespace Disney {
//   :
//    print()    IBM
extern void print( int );

++   437

   }

    using-  using-    
     .    
    . (Using-  using-
   8.6.)
     using-    ? ,  
         ,   
 .       ?

namespace libs_R_us {
int max( int, int );
int max( double, double );

extern void print( int );
extern void print( double );
}

// using-
using libs_R_us::max;
using libs_R_us::print( double ); // 

void func()
{
max( 87, 65 ); //  libs_R_us::max( int, int )
max( 35.5, 76.6 ); //  libs_R_us::max( double, double )

    using-    libs_R_us::max   
.     max()    func().  
 ,    .  using- 
 :      .  libs_R_us::print()
  :

using libs_R_us::print;

   Using-        
.   ,     libs_R_us 
 . ,    

print( 88 );

   ,     libs_R_us::print(int).
          
  ,    
.
    ,  using-       
 ?    ,      
 ,   using-.     
     ,   
 :

++   438

#include <string>
namespace libs_R_us {
extern void print( int );
extern void print( double );
}

extern void print( const string & );

// libs_R_us::print( int )  libs_R_us::print( double )
//  print( const string & )
using libs_R_us::print;

void fooBar( int ival )
{
print( "Value: "); //   
                       // print( const string & )
print( ival ); //  libs_R_us::print( int )
}

   Using-       : 
print(int)   print(double).     
libs_R_us         print,  
  print(const string &).    print 
fooBar    .
    using-      ,   
          ,  
.   using-     
print(int)    libs_R_us,      
 print(int). :

namespace libs_R_us {
void print( int );
void print( double );
}

void print( int );

using libs_R_us::print; // :   print(int)

void fooBar( int ival )
{
print( ival ); //  print? ::print  libs_R_us::print
}

    ,   using-   . 
   using-. Using-   ,
        , 
    .           ,
  . :

++   439

#include <string>
namespace libs_R_us {
extern void print( int );
extern void print( double );
}

extern void print( const string & );

// using-
// print(int), print(double)  print(const string &) - 
//       
using namespace libs_R_us;

void fooBar( int ival )
{
print( "Value: "); //   
                        // print( const string & )
print( ival ); //  libs_R_us::print( int )
}

        ,    using-.  ,
   ,      :

namespace IBM {
int print( int );
}
namespace Disney {
double print( double );
}

// using-
//      
//  
using namespace IBM;
using namespace Disney;
long double print(long double);
int main() {
print(1); //  IBM::print(int)
print(3.1); //  Disney::print(double)
return 0;
}

        print    
  print(int), print(double)  print(long double).  
  main()   ,   
    .
   , ,          
.  ,       using-
 using-,      .

++   440

9.1.5.  extern "C"    A

     7.7  ,    extern "C"   
  C++  ,  ,      ,
   C.       
?          ,  
 C++,    C?
            
. ,   :

// :       extern "C"
extern "C" void print( const char* );
extern "C" void print( int );

        calc()  
  extern "C":

class SmallInt ( /* ... */ );
class BigNum ( /* ... */ );
//   C       ,
//   C,    ,   C++.
//  C++  ,  
extern "C" double calc( double );
extern SmallInt calc( const SmallInt& );
extern BigNum calc( const BigNum& );

     C  calc()      C,     
C++.         , ,
       C++.   
.
         ,   ;
   .   ,   
   :

Smallint si = 8;
int main() {
calc( 34 ); //  C- calc( double )
calc( si ); //   C++ calc( const SmallInt & )
// ...
return 0;
}

9.1.6.     A

        . :

++   441

extern void ff( vector<double> );
extern void ff( unsigned int );
//     pf1?
void ( *pf1 )( unsigned int ) = &ff;

     ff() ,   &ff  
  .  ,    
,        ,  
       ,   ,  
 .       ff(unsigned int).
        ,     ? 
    :

extern void ff( vector<double> );
extern void ff( unsigned int );
// :   :   
void ( *pf2 )( int ) = &ff;
double ( *pf3 )( vector<double> ) = &ff;

     .      
  ,        
     .     
,     ,     .
 ,        
.

matrix calc( const matrix & );
int calc( int, int );
int ( *pc1 )( int, int ) = 0;
int ( *pc2 )( int, double ) = 0;
// ...
// :   calc( int, int )
pc1 = &calc;
// :  :    
pc2 = &calc;

9.1.7.   A

       ,     
      .  
       .  
  ,      

++   442

, ,     .  ,  ,
   .      print 
  ,         (  
     ).      
   print   .
      ,       
 ,     .  
      .   
  ,   .     , 
             
.
        8.2,   ,  ,  
      ,  
 ,          
.         
 ,     .
        ,    
extern "C",          
   .      , 
 extern "C",         .

 9.1

        ?

 9.2

         error(),   
 :

int index;
int upperBound;
char selectVal;
// ...
error( "Array out of bounds: ", index, upperBound );
error( "Division by zero" );
error( "Invalid selection", selectVal );

 9.3

   ,          
:

++   443

(a) int calc( int, int );
int calc( const int, const int );

(b) int get();
double get();

(c) int *reset( int * );
double *reset( double * ):

(d) extern "C" int compute( int *, int );
extern "C" double compute( double *, double );

 9.4

         ? ?

(a) void reset( int * );
void (*pf)( void * ) = reset;

(b) int calc( int, int );
int (*pf1)( int, int ) = calc;

(c) extern "C" int compute( int *, int );
int (*pf3)( int*, int ) = compute;

(d) void (*pf4)( const matrix & ) = 0;

9.2.    

            
,   .      
 .  :

T t1, t2;
void f( int, int );
void f( float, float );

int main() {
f( t1, t2 );
return 0;
}

             T ,
     f(t1,t2)   f(int,int) 
f(float,float)   .
             C++. 
   ,     
.          , 
  ,      - 

++   444

  .  ,    ,    
   .
          ,    
 :

void f();
void f( int );
void f( double, double = 3.4 );
void f( char *, char * );

void main() {
f( 5.6 );
return 0;
}

         :

  1.       ,  
       ,  .
  2.     ,      
     ,      .
  3.  ,     .

      .
          ,
     .     
 . -       ,  
,       .     
 : f(), f(int), f(double, double)  f(char*, char*).
         , .. 
  .          double.
           (viable)  ,
      ,    
   ,    
 ,  ,      
     .    , 
  ,   ,  
    ,   .
         ,     
 :

    f(int) ,         
         double  
      int;
    f(double,double) ,      
      ,       double,  
        .

          ,   
.     ,     .

++   445

        ,     .
      (  ).  
   ,   
        .
   ,     :

  ,    ,   ,
        ;

       ,  ,
            .

             9.3.
         .
   f(int)     
  double   int,    .  
 f(double,double)    double  
   .    
  (   ,  
),        
f(double,double).
              ,
 ,    ,     
,    , .. .
   (          9.4.
       -
   .   15.10  
 ,   - ,    15.11 
   .     
   ,   .   10.8
,      .)

 9.5

       ()     ?

9.3.    A

            
 ,      
        
     .    
   :

    .      
     . ,     
    print()  :

     void print( unsigned int );
     void print( const char* );
     void print( char );

++   446

            :

     unsigned int a;
     print( 'a' ); //  print( char );
     print( "a" ); //  print( const char* );
    print( a ); //  print( unsigned int );

      .    
       ,      :

     void ff( char );
     ff( 0 ); //   int    char

    .      
           , 
       .     
      print()  :

     //  print()   ,   
     int *ip;
     class SmallInt { /* ... */ };
     SmallInt si;
     print( ip ); // :  
     print( si ); // :  

          
     .     
  ,  :

    l-  r-;
      ;
      ;
    .
  (   .)

          . 
    :   (promotions),
     .
(        .
     , 
  ;   , -,
       
.   15        ,  
    .)

++   447

             
,       
 .     :
    ,    
,  ,   ,   
.        9.4,    
 ,       .

9.3.1.    

       ,      
  . ,     
 max().     max()    
:

int max( int, int );
double max( double, double );

int i1;

void calc( double d1 ) {
max( 56, i1 ); //   max( int, int );
max( d1, 66.9 ); //   max( double, double );
}

           
,   ,       :

enum Tokens { INLINE = 128; VIRTUAL = 129; };
Tokens curTok = INLINE;

enum Stat { Fail, Pass };

extern void ff( Tokens );
extern void ff( Stat );
extern void ff( int );

int main() {
ff( Pass ); //   ff( Stat )
ff( 0 ); //   ff( int )
ff( curTok ); //   ff( Tokens )
// ...
}

     ,      
 ,        
 ,      l-  r-
.  l-  ,   :

      ;
      ;

++   448

       (     
     const).

   , r-   ,   ,  ,
  ,       
  .   :

int calc( int );

int main() {
int lval, res;
lval = 5; // lvalue: lval; rvalue: 5
res = calc( lval );
// lvalue: res
// rvalue:     ,
//   calc()
return 0;
}

        lval   l-,   5 r-
.     res   l-,   , 
  ,   calc(),   r-.
       ,   ,  
,   l-:

int obj1;
int obj2;

int main() {
// ...
int local = obj1 + obj2;
return 0;
}

    obj1  obj2   l-.       main()
  obj1  obj2   . ,   
 ,    l-, 
 l-  r-.
      ,   ,   ,  
 l-,     r-:

#include <string>
string color( "purple" );
void print( string );

int main() {
print( color ); //  :  lvalue
//  rvalue
return 0;
}

++   449

        print(color)   ,  
 l-  r-    color    
   print(string).    ,   
 , ,    color  
 print(string).
            
.    l-;     -
,      l-.    ,
   -,   
. ,    :

#include <list>
void print( list<int> & );

      li   l-,   list<int>, 
 print():

list<int> li(20);
int main() {
// ...
print( li ); //  :   lvalue 
// rvalue
return 0;
}

    li  -   .
    ,       ,  
   .      7.3, 
     ,       
 .       NT ( N  
  ,  T    )      
T.        
  .   , ,    
      T. :

int ai[3];
void putValues(int *);
int main() {
// ...
putValues(ai); //  :   
// 
return 0;
}

      putValues()    ,  
   ai (   )     int.

++   450

       putValues()    
   ,     .
           
. (    7.9.)   -, -
   .     
      .   
       . 
 , ,     
 . :

int lexicoCompare( const string &, const string & );

typedef int (*PFI)( const string &, const string & );
void sort( string *, string *, PFI );

string as[10];

int main()
{
// ...
sort( as,
as + sizeof(as)/sizeof(as[0] - 1 ),
lexicoCompare //  
//    
);

return 0;
}

     sort()     , 
  lexicoCompare        .
     ,    
 , ,      ,
,        
sort().
          .  
        const  volatile
( )  ,    :

int a[5] = { 4454, 7864, 92, 421, 938 };
int *pi = a;
bool is_equal( const int * , const int * );

void func( int *parm ) {

//    pi  parm:  
if ( is_equal( pi, parm ) )
// ...

return 0;
}

++   451

      is_equal()   pi  parm 
    int     const int.  
    const   ,  
   .   ,   
    const int,     
 int, ,       
  is_equal() .
        ,   .
    ,      const
 volatile,     .

extern void takeCI( const int );

int main() {
int ii = ...;
takeCI(ii); //    
return 0;
}

       takeCI()   const int,   
  ii  int,    :  
      .
        ,    ,  
const  volatile    :

extern void init( int *const );
extern int *pi;

int main() {
// ...
init(pi); //    
return 0;
}

    const     init()   
,    ,   .    
,       , 
  .   pi   
: ,       
  .
        (l-  r-,  
    )    l-. (
 9.4  ,     l-,  
    ,   
,      ,    
.         .)
       ,  
 . ,     :

++   452

extern void ff(int);
extern void ff(void *);

 

   ff( 0xffbc ); //  ff(int)

   ff(int),   0xffbc   
 .     
 ff(void *),      :

   ff( reinterpret_cast<void *>(0xffbc) ); //  ff(void*)

         ,    , 
 .       
 . ,     
  (    
    ),     
   ,     .

9.3.2.    

          :

      char, unsigned char  short  
     int.    unsigned short    int,
       int ,   short,    unsigned int 
     ;
     float    double;
           ,
          : int,
    unsigned int, long, unsigned long;
     bool    int.

     ,       
    ,     
  :

extern void manip( int );
int main() {
manip( 'a' ); //  char   int
return 0;
}

       char.    int.  
      manip(),  ,  
    .

++   453

     :

extern void print( unsigned int );
extern void print( int );
extern void print( char );
unsigned char uc;
print( uc ); // print( int );  uc    

     ,   unsigned char    , 
int   ,   unsigned char  int,    
      unsigned char.   
        
   unsigned char  print(int).   
     .
         
:

enum Stat ( Fail, Pass );
extern void ff( int );
extern void ff( char );
int main() {
// :   Pass    int
ff( Pass ); // ff( int )
ff( 0 ); // ff( int )
}

       .   
       . ,
    (   char     int)
  :

enum e1 { a1, b1, c1 };

       : a1, b1  c1   0, 1  2   
       char,  ,  ,
  char    e1. , ,  e2 
  :

enum e2 { a2, b2, c2=0x80000000 };

          0x80000000,     
 e2  ,      0x80000000, 
 unsigned int.
   ,   e1,  e2  ,   . -
 e1  e2    :

++   454

#include <string>

string format( int );
string format( unsigned int );

int main() {
format(a1); //  format( int )
format(a2); //  format( unsigned int )
return 0;
}

       format()      int, 
    e1  char, , , 
  format(int).     
 e2   unsigned int     unsigned
int, -     format(unsigned int). 
 ,         
        , , 
  .

9.3.3.    

       ,  :

  1.   :        
        ( ,     
       );
  2.     :      
             ( ,
            );
  3.         :  
               ;
  4.  :    0    
           void*;
  5.    bool:     ,   
     ,        bool.

  :

extern void print( void* );
extern void print( double );

int main() {
int i;
print( i ); //  print( double );
// i     int 
double
print( &i ); //  print( void* );
// &i   
//  int*  void*
return 0;

++   455

   }

   ,    1, 2  3,  ,   
        . , 
 float       int.   
 ,    ,    
,    .

int i;
void calc( float );
int main() {
calc( i ); //        
//       
//  i
return 0;
}

      calc()      
int      float.      i 
,       float   .
   ,        .
,   char  unsigned char   ,   char
 double.      .    
      
,         .
   ,     :

extern void manip( long );
extern void manip( float );

   :

int main() {
manip( 3.14 ); // : 
// manip( float )  ,  manip( int )
return 0;
}

    3.14   double.      
        
.    ,   ,  
.        .
        :

   manip ( static_cast<long>( 3.14 ) ); // manip( long )

  , ,      float:

++   456

   manip ( 3.14F ) ); // manip( float )

        ,    ,
    :

extern void farith( unsigned int );
extern void farith( float );

int main() {
//     
farith( 'a' ); //    char
farith( 0 ); //    int
farith( 2uL ); //    unsigned long
farith( 3.14159 ); //    double
farith( true ); //    bool
}

        .  ,
 0      ;    
 .  0      
 :

void set(int*);

int main() {
//    0  int*   
//   
set( 0L );
set( 0x00 );
return 0;
}

     0L ( 0  long int)    0x00
(   0)       
     int*.
          , ,  0,  
  :

enum EN { zr = 0 };
set( zr ); // : zr     int*

     set()  ,      
 zr       int*,  zr
 0.
    ,    0   int.    
    .    
       int,      
   ,     0:

++   457

void print( int );
void print( void * );

void set( const char * );
void set( char * );

int main () {
print( 0 ); //  print( int );
set( 0 ); // 
return 0;
}

     print(int)    ,    
print(void*)    0   . 
  ,      
print(int).   set() ,   0  
       
.     ,  .
           
   void*,  void*        . 
 :

#include <string>
extern void reset( void * );

void func( int *pi, string *ps ) {
// ...
reset( pi ); //  : int*  void*
/// ...
reset( ps ); //  : string*  void*
}

             void*  
 ,       :

typedef int (*PFV)();
extern PFV testCases[10]; //    

extern void reset( void * );

int main() {
// ...
reset( textCases[0] ); // :   
                                //  int(*)()  void*
return 0;
}

++   458

9.3.4. 

           . 
     ?
,  ,     .  
   . -   l-,  
    :

int i;
int& ri = i;
void print( int );
int main() {
print( i ); //  -  lvalue  int
print( ri ); //   
return 0;
}

          int.    
         .
       ,  ,
  ,        T  
    . :

int i;
int& ri = i;
void calc( double );

int main() {
calc( i ); //     
//     
calc( ri ); //   
return 0;
}

       ,    , 
-?    :

         -.
        ,      :

     void swap( int &, int & );

     void manip( int i1, int i2 ) {
         // ...
         swap( i1, i2 ); // :  swap( int &, int & )
         // ...
         return 0;
     }

++   459

        -.  
       ,      
    . :

     int obj;
     void frd( double & );

     int main() {
        frd( obj ); // :      const double &
        return 0;
   }

      frd()  .     int 
         double,   
    -.     
    .      const,   
        .
       ,     - 
       :

     class B;
     void takeB( B& );
     B giveB();

     int main() {
        takeB( giveB() ); // :     const B &
        return 0;
    }

      takeB()  .     
    , ..  ,      
        const.
        ,    - 
     const,        
      .

    ,    l-  r-,  
   .      
  :

void print( int );
void print( int& );

int iobj;
int &ri = iobj;

int main() {
print( iobj ); // : 
print( ri ); // : 
print( 86 ); // :  print( int )
return 0;

++   460

   }

    iobj   ,        
 print(),    .       ,
  ri  ,    print().  
, ,   .   print(int&)   . 
   r-,       -.
     print(86)  print(int), 
     .
    ,      ,  
    ,   
 ,      .

 9.6

      ,    
.

 9.7

            :

(a) void print( int *, int );
int arr[6];
print( arr, 6 ); //  

(b) void manip( int, int );
manip( 'a', 'z' ); //  

(c) int calc( int, int );
double dobj;
double = calc( 55.4, dobj ) //  

(d) void set( const int * );
int *pi;
set( pi ); //  

 9.8

        - ,     
     :

++   461

(a) enum Stat { Fail, Pass };
void test( Stat );
text( 0 ); //  
(b) void reset( void *);
reset( 0 ); //  
(c) void set( void * );
int *pi;
set( pi ); //  
(d) #include <list>
list<int> oper();
void print( oper() ); //  
(e) void print( const int );
int iobj;
print( iobj ); //  

9.4.    

     9.2   ,       
 :

  1.   -    ,  
        .
  2.        ,   
                .
  3.  ,    ,  
     ,      , 
             .
       ,      .

9.4.1. -

   -  ,    ,   .
   :

        .   

void f();
void f( int );
void f( double, double = 3.4 );
void f( char*, char* );

int main() {
   f( 5.6 ); //       
return 0;
}

++   462

       f()   .  
       ;

          
    ,  -  ,    ,   
    ,    :

     namespace NS {
        class C { /* ... */ };
        void takeC( C& );
     }

     //  cobj -   C,     NS
     NS::C obj;

     int main() {
//          takeC()
takeC( cobj); // :  NS::takeC( C& ),
//      NS::C, ,
//     takeC(),
//     NS
return 0;

     }

    ,      ,
   ,   ,     
,      .
       ,    ,
    .
   ,     , ,   
    .      
    , .. ,     . 
  -,    , 
format(double)  format(char*):

char* format( int );
void g() {
char *format( double );
char* format( char* );
format(3); //  format( double )
}

     format(int),     , ,  
   -.
         using-,    :

++   463

namespace libs_R_us {
int max( int, int );
double max( double, double );
}
char max( char, char );
void func()
{
//     
//         max( char,
char )
max( 87, 65 );
max( 35.5, 76.6 );
max( 'J', 'L' );
}

    max(),     libs_R_us,   
.     max()   ; 
    -      
  func().    using-,  
  max()    libs_R_us.   using-
?       :

   char max( char, char );
   using libs_R_us::max; // using-

  max()  libs_R_us     ,
   max(),    .   
   func()   .    
func()   :

void func()
{
max( 87, 65 ); //  libs_R_us::max( int, int )
max( 35.5, 76.6 ); //  libs_R_us::max( double, double )
max( 'J', 'L' ); //  ::max( char, char )
}

     ,    using-     
func(),     ?

void func()
{
// using-
using libs_R_us::max;
//    ,   
}

++   464

      max()     ? ,  using-
    .      
   max(char, char)  ,    
  

libs_R_us::max( int, int );
libs_R_us::max( double, double );

   .   func()   :

void func()
{
// using-
//   max( char, char ) 
using libs_R_us::max;
max( 87, 65 ); //  libs_R_us::max( int, int )
max( 35.5, 76.6 ); //  libs_R_us::max( double, double )
max( 'J', 'L' ); //  libs_R_us::max( int, int )
}

   Using-       -.
,    ,    max() 
  libs_R_us   func().    using-
    ,   - 
    max(char, char)   max(int, int) 
max(double, double),   libs_R_us:

namespace libs_R_us {
int max( int, int );
double max( double, double );
}
char max( char, char );
using namespace libs_R_us; // using-
void func()
{
max( 87, 65 ); //  libs_R_us::max( int, int )
max( 35.5, 76.6 ); //  libs_R_us::max( double, double )
max( 'J', 'L' ); //  ::max( int, int )
}

    ,   using-    ,  
 ?

++   465

void func()
{
// using-
using namespace libs_R_us;
//    ,   
}

      max()   ? ,  using-
    ,      
,   ,    .    
libs_R_us      func(),     
    .  ,   
,   func(),  ,   , ..   

max( char, char );
libs_R_us::max( int, int );
libs_R_us::max( double, double );

          using-, 
   func()  :

void func()
{
using namespace libs_R_us;
max( 87, 65 ); //  libs_R_us::max( int, int )
max( 35.5, 76.6 ); //  libs_R_us::max( double, double )
max( 'J', 'L' ); //  ::max( int, int )
}

   ,     ,    ,   ,
  using-  using-,    ,
   ,     .
:

++   466

namespace basicLib {
int print( int );
double print( double );
}
namespace matrixLib {
class matrix { /* ... */ };
void print( const maxtrix & );
}
void display()
{
using basicLib::print;
matrixLib::matrix mObj;
print( mObj ); //  maxtrixLib::print( const maxtrix & )
print( 87 ); //  basicLib::print( const maxtrix & )
}

     print(mObj)   using- 
display()  basicLib::print(int)  basicLib::print(double), 
    .       
matrixLib::matrix,   print(),     matrixLib,
  .  -  print(87)? 
basicLib::print(int)  basicLib::print(double),    .
    int,      
  .

9.4.2.  

        .     
     ,       
,  .       
  ,        
.    ,   
       .
(      9.3.)
        f(5.6)    : f(int) 
f(double).

void f();
void f( int );
void f( double );
void f( char*, char* );
int main() {
f( 5.6 ); // 2  : f( int )  f( double )
return 0;
}

    f(int) ,        , 
     .  , 
    double  int.  f(double) 

++   467

;       double,    
 . - f()  f(char*, char*)  
 ,          .
           format(3)
 format(double).   format(char*)    
,        int  
  char*,  ,     .

char* format( int );
void g() {
//   format( int ) 
char* format( double );
char* format( char* );
format(3); //     : format( double )
}

        -    
max()  func().        . 
    int,    
  libs_R_us::max(int, int)      
  libs_R_us::max(double, double)   
  ,       libs_R_us::max(char,
char)    .

namespace libs_R_us {
int max( int, int );
double max( double, double );
}

// using-
using libs_R_us::max;

char max( char, char );
void func()
{
//    max()  
max( 87, 65 ); //  using libs_R_us::max( int, int )
}

    ,  -     
 ,   ,       
      ,    
    .    
min(char *, int)    ,   
    int     char *.
     ,      
.

++   468

extern double min( double, double );
extern double min( char*, int );

void func()
{
//  - min( double, double )
min( 87, 65 ); //  min( double, double )
}

            
   ,      
,   ,     
 .    ,    .

void print( unsigned int );
void print( char* );
void print( char );

int *ip;
class SmallInt { /* ... */ };
SmallInt si;

int main() {
print( ip ); // :   :  

print( si ); // :   :  

return 0;
}

9.4.3.    

        ,   
     .    
 ,    ,  
    . (  6.2 
  .)     ,
     :

   ,   ,   ,
          ;
          ,   
          .

      ,       
      .
,   

++   469

int arr[3];
void putValues(const int *);

int main() {
putValues(arr); //  2 
//    +  
return 0;
}

   arr      int     const
int   :

  1.    ,      int 
       int.
  2.  ,     int 
       const int.

        ,     
       
.    ,   ,  
         
 .
             
.     9.2,   
 :     ,   
  .       
 .        .
        ,   
:

    l- ->
           ->
          

     l-      
  ,    9.2:  l-
 r-,         .
        l-
,          
,       . 
        
     .
       
.     
,    -,   .
(     
   15.)
          ?

++   470

namespace libs_R_us {
int max( int, int );
double max( double, double );
}
// using-
using libs_R_us::max;
void func()
{
char c1, c2;
max( c1, c2 ); //  libs_R_us::max( int, int )
}

       max()   char. 
     libs_R_us::max(int,int) :

  1a.      ,   
       l-  r-    c1 
      c2.
  2a.        char 
      int.

        
libs_R_us::max(double,double) :

  1b.    l-  r-  
       c1  c2.
  2b.        
         char   double.

         (   
),       .   
 ,  ,        
   libs_R_us::max(int,int).
          
  ,    .  
    calc()   :

  1.  l-  r-     i 
     j.
  2.        
        .

     ,      , 
:

++   471

int i, j;
extern long calc( long, long );
extern double calc( double, double );

void jj() {
// : ,   
calc( i, j );
}

     (  const  volatile 
,   )    . ,  
    ,      
   ,    
 . :

void reset( int * );
void reset( const int * );
int* pi;
int main() {
reset( pi ); //    :
//  reset( int * )
return 0;
}

     ,   
   - reset(int*),    ,
    l-  r-,    .
  - reset(const int *)  
 l-  r-,       
         int 
   const int.     
,      .   
       
,       . 
     reset(int*).
     ,       , 
  :

int extract( void * );
int extract( const void * );
int* pi;

int main() {
extract( pi ); //  extract( void * )
return 0;
}

++   472

         : extract(void*)  extract(const
void*).     extract(void*)  
 l-  r-    ,
   :    int 
  void.   extract(const void*)  
       
     void    const void. 
    ,    
  , ,     
extract(const void*).
    const  volatile     
-.       
 const  volatile,     
    :

#include <vector>
void manip( vector<int> & );
void manip( const vector<int> & );

vector<int> f();
extern vector<int> vec;

int main() {
manip( vec ); //  manip( vector<int> & )
manip( f() ); //  manip( const vector<int> & )
return 0;
}

             
.        .   
   ,     const
  ,       , 
       manip(vector<int>&).
           manip(const
vector<int>&).      ,
 ,  f(),      r-
,       
-  manip(vector<int>&).   
  manip(const vector<int>&).
   ,       . 
       
   .  :

extern int ff( char*, int );
extern int ff( int, int );
int main() {
ff( 0, 'a' ); // ff( int, int )
return 0;

++   473

   }

    ff(),     int,    
    :

  1.    . 0      
      int,         char *
        ;
  2.       .   'a'  char  
              
        ,   
     .

      :

int compute( const int&, short );
int compute( int&, double );

extern int iobj;

int main() {
compute( iobj, 'c' ); // compute( int&, double )
return 0;
}

     compute( const int&, short )  compute( int&, double ) .
       :

  1.    .      
      ,      const,   
      ;
  2.       .   'c'  char  
              
        ,   
     .

9.4.4.     

           
 .   ,    
  .       
,    ,   ,   
      :

++   474

extern void ff( int );
extern void ff( long, int = 0 );

int main() {
ff( 2L ); //  ff( long, 0 );
ff( 0, 0 ); //  ff( long, int );
ff( 0 ); //  ff( int );
ff( 3.14 ); // : 
}

         ff()  ,   
  .    :

  1.        ;
  2.    long      
                 
     ,    .

      ,     
 ,       .
 ff(int)     ,     .

 9.9

   ,         compute()
 main().    ?     
 ?      
 ,       
 ?      ?

   namespace primerLib {
      void compute();
      void compute( const void * );
   }

   using primerLib::compute;
   void compute( int );
   void compute( double, double = 3.4 );
   void compute( char*, char* = 0 );

   int main() {
      compute( 0 );
      return 0;
   }

    ,  using-   main()   compute()?
    .
