

                7

             ᫨  롨 ᫮,   ⮫쪮 ,
               ,     .
                         - ⠩ ⠩


        ᮤন ᠭ 堭 ॣ㧪 権  ++.
       ணࠬ    権,  
       ਬ  ꥪ⠬ । .  䬥᪨,
       ᪨  権 ⭮襭  ८। 맮
       㭪権 (),  [], ᢥ 饭 ->,  ⠪
       ᢠ  樠.  ।   
       ८ࠧ  짮⥫᪨  ᭮묨 ⨯. ,
        । , ꥪ ண  ஢ 
       㭨⮦ ⮫쪮   ᯥ樠, । 짮⥫
       㭪権.

   7.1 

   筮  ணࠬ ᯮ ꥪ, 騥 
   ।⠢ ࠪ ⨩. ਬ,  ++ ⨯  int
     ﬨ +, -, *, /  .. ॠ (  ࠭祭)
   ⥬᪮ ⨥ 楫. 筮  ⨥ 뢠 
   ⢨,  ॠ  몥   ᭮ 権 
   ꥪ⠬,   ᦠ⮬, 㤮  ਢ筮 .
    ᮦ,  몠 ணࠬ஢ ।⢥ ।⠢
   ⮫쪮  ᫮ ⨩. ,   ᥫ, 
   , ᪨ ᨣ  ப  ++   ।⢥
   ࠦ.   ।⠢ ᫮ ꥪ⮢ 
    ஬ 権, 믮塞  ⠪ ꥪ⠬,
   ॠ  ++ .  ணࠬ । 樨
    ꥪ⠬ ᮢ,  砥  㤮  ࠤ樮
   ⥬ 祭  ࠡ  ⨬ ꥪ⠬  ࠢ  ⮩,
    ன  樨    㭪樨. ਢ ਬ:

           class complex {
             double re, im;
           public:
             complex(double r, double i) { re=r; im=i; }
             friend complex operator+(complex, complex);
             friend complex operator*(complex, complex);
          };

    ਢ  ॠ  ᭮ ᫠, 
    ।⠢ ன ᥫ  饩 窮  筮,
    묨  ஢ ⮫쪮   権 +  *.
     権  ணࠬ  । 㭪権
     operator+  operator*. , ᫨ b  c  ⨯ complex,
    b+c 砥 ( ।) operator+(b,c).  
   ਡ  ਢ筮   ࠦ:

         void f()
         {
           complex a = complex(1,3.1);
           complex b = complex(1.2,2);
           complex c = b;

           a = b+c;
           b = b+c*a;
           c = a*b+complex(1,2);
         }

   ࠭  ਮ 権, ⮬ ஥ ࠦ
   믮  b=b+(c*a),    b=(b+c)*a.

  7.2  㭪樨

    㭪樨, ।騥  ᫥ 権:

        +    -    *    /    %    ^    &    |    ~    !
        =    <    >    +=   -=   *=   /=   %=   ^=   &=
        |=   <<   >>   >>=  <<=  ==   !=   <=   >=   &&
        ||   ++   --   ->*  ,    ->   []   ()   new  delete

   ᫥  権 : ᢥ 饭 ($$7.9),
    ($$7.7), 맮 㭪樨 ($$7.8), ࠧ饭  ᢮
     ᢮ ($$3.2.6).   ਮ 
   権, ࠢ   ᨭ⠪᪨ ࠢ  ࠦ. ,
    । 㭠  % , ⠪    
   !.    ᥬ  祭 権,  ᫨
    権   ࠨ,  ᯮ짮 ਢ
   祭 맮 㭪樨. ⮬ ᯮ pow(),   ** .
    ࠭祭   ࠪ᪨,   ᢮
   ࠢ  ਢ  筮. ⨬,  ।
    **    ⥯,     
   祢  ⮩ 祩.  ᫨  ᫥ 㬠, 
    :   樨 ** 믮 ᫥ ࠢ
   (  ࠭)  ࠢ  (  )? 
   ஢ ࠦ a**p  a*(*p)   (a)**(p)?
       ୮ 㭪樨  㦥 ᫮ operator, 
     ᠬ , ਬ, operator<<. ୠ
   㭪 뢠  뢠  筠 㭪. ᯮ짮
   ᨬ 樨   ⪮ ମ  맮
   ୮ 㭪樨:

           void f(complex a, complex b)
           {
             complex c = a + b;           // ⪠ ଠ
             complex d = operator+(a,b);  //  맮
           }

    ⮬ ਢ ᠭ ⨯ complex 樠  ⮬
   ਬ  묨.

   7.2.1   㭠 樨

      ।  㭪-童  
   ࠬ஬,    㭪   ࠬࠬ. ,
     ୮ 樨 @ ࠦ aa @ bb 
     aa.operator(bb),   operator@(aa,bb). ᫨ । 
   㭪樨,  롮 樨 ந室  ࠢ ᮯ⠢
   ࠬ஢ ($$R.13.2). 䨪᭠  䨪᭠ 㭠ୠ 
    ।  㭪-童  ࠬ஢,   쭠
   㭪   ࠬ஬.   䨪᭮ 㭠୮ 樨
   @ ࠦ @aa    aa.operator@(),  
   operator@(aa). ᫨ ।  㭪樨,  롮 樨
   ந室  ࠢ ᮯ⠢ ࠬ஢ ($$R.13.2). 
    䨪᭮ 㭠୮ 樨 @ ࠦ @aa 
     aa.operator@(int),   operator@(aa,int). ஡
      $$7.10. ᫨ ।  㭪樨,  롮
   樨 ந室  ࠢ ᮯ⠢ ࠬ஢
   ($$13.2).   । ⮫쪮  ᮮ⢥⢨ 
   ᨭ⠪᪨ ࠢ, 騬    ࠬ⨪ ++.
    ⭮,  । %  㭠 ,  + 
   ୠ. ந㥬 ᪠ ਬࠬ:

           class X {
             // 童 ( ᯮ 㪠⥫ `this'):

             X* operator&();        // 䨪᭠ 㭠ୠ  &
                                    // (⨥ )
             X operator&(X);        // ୠ  & ( ࠧ來)
             X operator++(int);     // 䨪 ६
             X operator&(X,X);      // 訡: &    ୠ୮
             X operator/();         // 訡: /    㭠୮
           };

          //  㭪樨 (筮 )

           X operator-(X);          // 䨪 㭠 
           X operator-(X,X);        //  
           X operator--(X&,int);    // 䨪 ६
           X operator-();           // 訡:  ࠭
           X operator-(X,X,X);      // 訡: ୠୠ 
           X operator%(X);          // 訡: 㭠ୠ  %

    [] 뢠  $$7.7,  ()  $$7.8,  ->
    $$7.9,  樨 ++  --  $$7.10.

   7.2.2 ।। ᢮⢠ 権

   ᯮ ⮫쪮 ᪮쪮 ।  ᢮⢠ 짮⥫᪨
   権.  ⭮, operator=, operator[], operator() 
   operator->   ᪨ 㭪ﬨ-童. ⨬
   ᯥ稢 ,   ࠭  権  ᮬ.
        ஥ 権   ।
     㣨 権, 믮塞  ⥬  ࠭.
   , ᫨ a ⨯ int,  ++a 砥 a+=1,   ᢮ ।
   砥 a=a+1.  ᮮ⭮襭  ࠭  짮⥫᪨
   権, ᫨ ⮫쪮 짮⥫ ᯥ樠쭮  ।   ⠪
   楫. , । operator+=()  ⨯ complex  뢥
    । complex::operator+()  complex operator=().
       ᪮ 砩 ,  樨 = (ᢠ),
   &(⨥ )  , ( )  ।।묨
   ᢮⢠  ꥪ⮢ ᮢ.     ந쭮
   짮⥫  ᢮⢠, ᫨   樨  :

           class X {
              // ...
           private:
              void operator=(const X&);
              void operator&();
              void operator,(const X&);
              // ...
           };

           void f(X a, X b)
           {
              a= b;   // 訡:  = ⭠
              &a;     // 訡:  & ⭠
              a,b     // 訡:  , ⭠
           }

    㣮 ஭,   ਤ   ᮮ⢥
   । ⨬   祭.

   7.2.3  㭪樨  짮⥫᪨ ⨯

   ୠ 㭪    童,    ࠩ
     ࠬ, 騩 ꥪ⮬  ( 㭪権,
   ८। 樨 new  delete,   易⥫쭮). 
   ࠢ ࠭,  짮⥫  㬥 
    ࠦ,  ᮤঠ ꥪ⮢ 짮⥫᪮
   ⨯.  ⭮,  ।  㭪, ࠡ
   ⮫쪮  㪠⥫ﬨ. ⨬ ࠭,   ++ 
   ७,   樨 (  権 =, &,  ,  ꥪ⮢
   ).
       ୠ 㭪,   ࠬ ᭮ ⨯,
      㭪樥-童. , ᫨  ਡ塞 
   ६ aa  楫 2,   室饬 ᠭ 㭪樨-童
   aa+2  ஢  aa.operator+(2),  2+aa ⠪
   ஢ , ᪮    int, 
   ண + ।  2.operator+(aa).  ᫨   뫮
   ,  樨 aa+2  2+aa 諮    
   ࠧ묨 㭪ﬨ-童.  ਬ ਢ쭮 뢠
     㭪権,   童.
       ࠦ ஢   筮⥩.
   ᫨ 짮⥫᪨ 樨   
   ࠦ,  ஢  ᮮ⢥⢨  ࠢ $$R.13.2.

   7.3 짮⥫᪨ 樨 ८ࠧ ⨯

   ᠭ   ॠ ᭮ ᫠  ᫨誮
   ࠭祭, ⮡ 㤮⢮ -,    .
     ७ ᠭ ⮣  ,  㦥 뫨
   ਬ:

          class complex {
            double re, im;
          public:
            complex(double r, double i) { re=r; im=i; }

            friend complex operator+(complex, complex);
            friend complex operator+(complex, double);
            friend complex operator+(double, complex);

            friend complex operator-(complex, double);
            friend complex operator-(complex, double);
            friend complex operator-(double, complex);
            complex operator-();  // 㭠 -

            friend complex operator*(complex, complex);
            friend complex operator*(complex, double);
            friend complex operator*(double, complex);

            // ...
          };

     ⠪ । ᭮ ᫠,  :

         void f()
         {
           complex a(1,1), b(2,2), c(3,3), d(4,4), e(5,5);
           a = -b-c;
           b = c*2.0*c;
           c = (d+e)*a;
         }

    -⠪ ⮬⥫쭮,    ⮫쪮    operator*()
       樨 complex  double ᢮ 㭪. 
    ⮣, ࠧ㬭 ।⢠  ᭮ 䬥⨪ 
    ।⠢ ⪨ ⠪ 㭪権 (ᬮ, ਬ, 
    ᠭ ⨯ complex  <complex.h>).

    7.3.1 

     ⮣, ⮡ 뢠 ᪮쪮 㭪権,  
    ,   ࠬ double ᮧ complex:

           class complex {
              // ...
              complex(double r) { re=r; im=0; }
           };

    ⨬ ।   complex, ᫨  double. 
    ࠤ樮 ᯮᮡ ७ ⢥ אַ  ᭮
    ᪮.
          ⢥ ࠬ஬  易⥫쭮 뢠
    :

           complex z1 = complex(23);
           complex z2 = 23;

     ६ z1  z2  樠஢ 맮 complex(23).
          ⬮ ᮧ 祭  ⨯.
    ᫨ ॡ 祭 ண ⨯   騩 
    , ࠬ஬ ண   祭,  ⮣
       㤥 ᯮ짮. ,  complex 
    뫮  ᫥騬 ࠧ:

           class complex {
              double re, im;
           public:
              complex(double r, double i =0) {  re=r; im=i; }

              friend complex operator+(complex, complex);
              friend complex operator*(complex, complex);

              complex operator+=(complex);
              complex operator*=(complex);

              // ...
           };

     樨  묨 ६묨  楫묨 ⠭⠬
     ⮬ ⮣ ᠭ ⠭ 묨.  ⠭
    㤥 ஢  ᭮ ᫮   ,
    ࠢ . , a=b*2 砥
           a = operator*(b, complex( double(2), double(0) ) )
     ᨨ 権 ⠪,  + ,   । ⮫쪮,
    ᫨ ࠪ⨪ ,  襭 䥪⨢   ⪠
     ८ࠧ ⨯ ⮨ ⮣. ਬ, ᫨ ᭨, 
     㬭 ᭮ ६  ⢥
    ⠭  筮,    権 
     operator*=(double):

          class complex {
            double re, im;
          public:
            complex(double r, double i =0) { re=r; im=i; }

            friend complex operator+(complex, complex);
            friend complex operator*(complex, complex);

            complex& operator+=(complex);
            complex& operator*=(complex);
            complex& operator*=(double);

            // ...
          };

    樨 ᢠ ⨯ *=  +=   祭 묨
     ࠡ  짮⥫᪨ ⨯, ᪮ 筮 
      , 祬   묨 "" *  + ,  ஬ ⮣
       ᪮ 믮 ணࠬ  
    ᪫祭 ६ ६:

           inline complex& complex::operator+=(complex a)
           {
              re += a.re;
              im += a.im;
              return *this;
           }

     ᯮ짮 ⮩ 㭪樨  ॡ ६ ६
     ࠭ १,   筮 , ⮡ ࠭
     "쭮" ந ⠭ ⥫.   樨
     ᫮  ⮦   ।⢥:

           inline complex operator+(complex a, complex b)
           {
             return complex(a.re+b.re, a.im+b.im);
           }

       return ᯮ ,   ࠭
    業 ᪠  । ⨬樨.    ᫮
    ⨯  権, ਬ ⠪,  㬭 , १
        ࠦ, ⮣ 樨 *  + 
    ॠ   *=  += ,     
    ⨬樨:

           matrix& matrix::operator*=(const matrix& a)
           {
              // ...
              return *this;
           }

           matrix operator*(const matrix& a, const matrix& b)
           {
             matrix prod = a;
             prod *= b;
             return prod;
           }

    ⬥⨬,   ।  ࠧ 樨  㦭
     ᮡ ࠢ 㯠  ,  ஬  ਬ,
    ..      㣮  童 ⮣ .
       짮⥫᪮ ८ࠧ ⨯ ਬ ⮫쪮  ⮬
    砥, ᫨  ⢥($$7.3.3).
      ஥  १    맮 ,
    ꥪ  ⮬᪨,  㭨⮦  ࢮ
    ,-  ࠢ ࠧ ᫥ 믮 , 
    ஬   ᮧ.

    7.3.2 樨 ८ࠧ

     㤮 ᯮ짮  ८ࠧ ⨯,  
    ⥫ ᫥⢨:
      [1]  ८ࠧ  짮⥫᪮ ⨯  ᭮
           (᪮ ᭮ ⨯   ᠬ).
      [2]   ८ࠧ   ⨯  , 
           ᠭ ண ⨯.
      [3]  ।    ࠬ஬,  ।
          ⥬ ᠬ  ८ࠧ ⨯.
       ᫥   让 ஡,    
    ८, ᫨ ।  㭪 ८ࠧ
     室 ⨯. 㭪-童 X::operator T(),  T - 
    ⨯, । ८ࠧ ⨯ X  T. ਬ, 
    । ⨯ tiny (), 祭 ண 室 
     0..63,   ⨯   䬥᪨  ࠪ᪨
    ᢮ ᬥ訢  楫묨:

            class tiny {
              char v;
              void assign(int i)
              { if (i>63) { error("室  "); v=i&~63;  }
                v=i;
              }
            public:
              tiny(int i) { assign(i) }
              tiny(const tiny& t) { v = t.v; }
              tiny& operator=(const tiny& t)
                 { v = t.v; return *this; }
              tiny& operator=(int i) { assign(i); return *this; }
              operator int() { return v; }
            };

       ஢   樠樨 ꥪ
    tiny, ⠪   ᢠ  int.  ꥪ tiny 
    ᢮ 㣮  ஫ .  믮 
    権  楫묨  ६ ⨯ tiny । 㭪
    tiny::operator int(), ந  ८ࠧ ⨯
     tiny  int. ,  ॡ int,   ६ ⨯
    tiny, ᯮ ८ࠧ  int 祭:

             void main()
             {
               tiny c1 = 2;
               tiny c2 = 62;
               tiny c3 = c2 -c1;  // c3 = 60
               tiny c4 = c3;      // ஫   (  㦥)
               int i = c1 + c2;   // i = 64
               c1 = c2 + 2 * c1;  // 室  : c1 = 0 (  66)
               c2 = c1 - i;       // 室  : c2 = 0
               c3 = c2;           // ஫   (  㦥)
             }


            ꥪ⮢ tiny, ᪮
      . ⮡ ⠪ ⨯ 뫮 㤮
   ᯮ짮,  ᯮ짮 樥 樨 [].
      짮⥫᪨ 樨 ८ࠧ ⨯  ਣ
   ࠡ  ⨯, ॠ騬 ⠭ ।⠢ ᥫ
  (䬥⨪  ᭮ 100, 䬥⨪ ᥫ  䨪஢ 窮,
  ।⠢  筮-筮   ..).  ⮬ 筮
  室 ८। ⠪ 樨,  +  *.
      ᮡ 묨 㭪樨 ८ࠧ ⨯ 뢠 
 ࠡ  ⠪ ࠬ ,   ⥭ (ॠ
   ८ࠧ)  ਢ,  ᢠ 
 樠 ⢥  ᫮ 樨.
      㭪樨 ८ࠧ 㦭  ⨯ istream  ostream, ⮡
 ⠫ 묨, ਬ, ⠪ :

           while (cin>>x) cout<<x;

   cin>>x 頥 祭 istream&.  
 ८ࠧ  祭, 뢠饥 ﭨ ⮪ cin, ஥
 ⥬ ஢   while (. $$10.3.2).  -⠪
 ।  ८ࠧ ⨯,  ஬  
 ८ࠧ㥬 祭,  ࠢ, 宥 襭.
       ,   짮 ﬨ ८ࠧ.
 ⮪ ⠪ 権  뢠 讥 ᫮ 筮⥩.
 ࠭ 㦨  筮,  ࠧ  
  ᮢᥬ .  砫   ८ࠧ
 ᯮ짮  㭪樨, ਬ, X::intof(),  ⮫쪮
 ᫥ ⮣,  ⠪ 㭪  ᫥ ஡,  
 ८ࠧ ⨯ 㤥 ⥭  襭, 
  ୮ 㭪樥 ८ࠧ X::operator int().

 7.3.3 筮

 ᢠ  樠 ꥪ  X  ,
 ᫨ ᢠ 祭  ⨯ X,  ᫨ 
 ⢥ ८ࠧ   祭 ⨯ X.
        祭 㦭 ⨯ ந  
  ਬ ஢  権 ८ࠧ.
     ࠧ, ⨬  짮⥫᪮
 ८ࠧ ⮫쪮  ஢ .   
  ᪮쪮 ᯮᮡ ஥ 祭 㦭 ⨯, 
   . ਢ ਬ:

         class x { /* ... */ x(int); x(char*); };
         class y { /* ... */ y(int); };
         class z { /* ... */ z(x); };

         x f(x);
         y f(y);

         z g(z);

         void k1()
         {
           f(1);      // ⨬, 筮: f(x(1))  f(y(1))
           f(x(1));
           f(y(1));
           g("asdf"); // ⨬, g(z(x("asdf")))  ᯮ
         }

     짮⥫᪨ ८ࠧ ⨯ ᬠਢ ⮫쪮  ⮬
  砥,     筮  뢠 㭪:

          class x { /* ... */ x(int); };

          void h(double);
          void h(x);

          void k2()
          {
            h(1);
          }

   맮 h(1)  ஢   h(double(1)),  
   h(x(1)), ⮬  ᨫ ॡ 筮   
   .  ᪮  ࢮ 樨 ᯮ
   ⮫쪮 ⠭⭮ ८ࠧ,   ࠢ, 㪠  $$4.6.6
    $$R.13.2, 롨ࠥ .
       ࠢ  ८ࠧ ⨯  ᫨誮  㫨஢
    ॠ,     筮 魮. ᬮਬ
   ॡ ⢥  ८ࠧ.  ᥣ
   ࠧ ࠭ ਬ  ८ࠧ, ஥ 
   㬥 .   ᭥ ४⭮ ࠦ  㦭
   ᬠਢ  騥 ८ࠧ.  ᮦ,  ⠪
   砥  ணࠬ 㤥   ⮣,  
   ८ࠧ .  १  ணࠬ 㤥
     浪 ᠭ ८ࠧ. ᪮  
   ᠭ ࠧᠭ  ࠧ 室 䠩 (ᮧ, ,
   ࠧ묨 ணࠬ⠬),  १ ணࠬ 㤥 
     浪  䠩 ᫨  ணࠬ.  㣮 ஭,
       ८ࠧ,   ᠬ
   ⮥ 襭.  १⮬ 㤥 ⢥ 䥩,
   ।塞 짮⥫,  뢭  ॣ㦥
   㭪権  権,      ਬ  complex
    ।饣 ࠧ.
        ᠬ 饬 室 뢠  ᢥ
    ⨯  ᬠਢ  騥 ८ࠧ.
   ਬ,  ⮬ ਢ ᠭ  ᢠ aa=f(1)
    ࠧ  맮 f(1), ᪮ ⨯ aa 
   ⢥ ८ࠧ. ᫨ aa  ⨯ x,  ⢥
   ८ࠧ 㤥 f(x(1)), ᪮ ⮫쪮   㦭
      ⨯ x. ᫨ aa  ⨯ y, 㤥 ᯮ짮
   f(y(1)).  ᠬ 饬 室 㤠 ࠧ   맮
   g("asdf"), ᪮ g(z(x("asdf)))   ⢥
   樥. 㤭 ⮣ 室  ⮬,  ॡ
   ᪮ ࠧ ᥣ ࠦ, ⮡ ⠭ 
    樨  맮 㭪樨.  १ ࠭
   , ᫥ ࠦ  ந ࠭ ࠧ
      ᮮ饭  訡,  ࠭
   뢠 ।  ⥪ ८ࠧ  ..
    १ ࠭ 室 뢠  ଠ樨,
   祬 ⭮ ᠬ ணࠬ! ࠭ 室,  ஬
   ஢ઠ  ண 室騬 ᮬ,   
    ᬠਢ ⮫쪮    ࠭, ⨯
    㦥 諨 ஢.
       ॡ ண 室饣 ࠧ ࠦ ।,
    ⨯ 頥 祭  뢠  ࠧ襭
   ॣ㧪:

            class quad {
               // ...
            public:
               quad(double);
               // ...
            };

            quad operator+(quad,quad);

            void f(double a1, double a2)
            {
              quad r1 = a1+a2;       // ᫮   筮
              quad r2 = quad(a1)+a2; // 㦤 ᯮ짮
                                     // 樨  ⨯ quad
            }

    ஥஢ 몠    ண 室騩 ࠧ,
   ᪮   ,  ஬ ⮣,   ࠭
    ⠪ ,  筮  ᫮ 
   ணࠬ.
       ,  ⬥,  ᫨ । ⨯  ⥩
    ᢠ  樠樨,    ࠧ襭 ᯮ
    :

            class real {
               // ...
            public:
               operator double();
               operator int();
               // ...
            };

            void g(real a)
            {
              double d = a;  // d = a.double();
              int i = a;     // i = a.int();

              d = a;         // d = a.double();
              i = a;         // i = a.int();
            }

    ⮬ ਬ ࠦ  ࠢ ࠧ ண 室騬
   ⮤,     ᬠਢ ⮫쪮  
    ⨯  ࠭.

   7.4 ࠫ

    ᮢ  । ࠫ 祭, 
   ⮬  1.2  12e3  ࠫ ⨯ double. ,
    樨 祭 ᮢ  ᯮ짮 
   㭪権-童 ࠫ ᭮ ⨯. 騬 ।⢮ 
   ஥ ⠪ 祭 㦠   ⢥
   ࠬ஬. ᫨  筮 ⮩  ॠ
   ⠭,  ࠧ㬭 ।⠢  맮 
   ࠫ. ਬ,  ⮬ ᠭ  complex  <complex.h>
    ࠦ zz1*3+zz2*complex(1,2) ந  맮 㭪権,
     .  樨 * ਢ  맮 㭪樨,  
   +  맮   ஥ complex(3)  complex(1,2)
    ॠ ⠭.

   7.5 訥 ꥪ

    믮  ୮ 樨  ⨯ complex ॠ饩
     㭪樨  ।  ࠬ  
   ࠭. ⥫ 室, 맢 ஢ 
   祭 ⨯ double, ,   ᥩ  ⨬.
    ᮦ ।⠢   ᮢ  ⮫ 㤮
   . ⮡  筮 ஢, 
   । 㭪樨  ࠬࠬ ⨯ 뫪:

             class matrix {
                double m[4][4];
             public:
                matrix();
                friend matrix operator+(const matrix&, const matrix&);
                friend matrix operator*(const matrix&, const matrix&);
             };

       뫪   譥 ஢ ᯮ짮
   ࠦ  묨 䬥᪨ ﬨ   
   ꥪ⮢. ⥫  ⮩ 楫 ᯮ짮 , ..
    ८।  樨, ᫨ 
   ਬ  㪠⥫.      ।
   ⠪:

             matrix operator+(const matrix& arg1, const& arg2)
             {
                matrix sum;
                for (int i = 0; i<4; i++)
                    for (int j=0; j<4; j++)
                        sum.m[i] [j] = arg1.m[i][j] + arg2.m[i][j];
                return sum;
             }

     㭪樨 operator+() ࠭ 롨  뫪, 
   頥 ᠬ 祭 ꥪ.  䥪⨢ 襭
      ⮦ 뫪:

             class matrix {
                // ...
                friend matrix& operator+(const matrix&, const matrix&);
                friend matrix& operator*(const matrix&, const matrix&);
             };

    ⨬,   ஡  뤥 . ᪮
   뫪  १ 樨 㤥 ।  뫪 
   頥 㭪樥 祭,     ⮬᪮
   ६ ⮩ 㭪樨. ᪮   ᯮ짮
   ⭮   ࠦ, १    
   쭮 ᪮ ६.  ࠢ, १ 㤥
   뢠  ⢥  ᢮  ꥪ. 筮
   뢠 襢 ( ⠬  ६ 믮   
    ) ஢ १饥 祭, 祬 ࠧ 
    ᢮   ⥬  筮  ᢮ 뤥
   .  ⮬   ᯮᮡ  ணࠬ஢.

   7.6 ᢠ  樠

   ᬮਬ ⮩ ப  string:

               struct string {
                  char* p;
                  int size;  // ࠧ ,   㪠뢠 p

                  string(int size) { p = new char[size=sz]; }
                  ~string() { delete p; }
               };

   ப -   , ᮤঠ 㪠⥫  
   ᨬ  ࠧ ⮣ .  ᮧ ஬ 
   㤠 ஬.      $$5.5.1  
    ஡:

               void f()
               {
                 string s1(10);
                 string s2(20)
                 s1 = s2;
               }

      ࠧ饭  ᨬ ,   १
    ᢠ s1 = s2 㪠⥫     㤥 㭨⮦,
       ண.  室  f() 㤥 맢  s1
     s2 ,   㤠     ,
    १ 祣  ᥩ   祢.  襭
    ⮩ ஡ 㦭 । ᮮ⢥饥 ᢠ
    ꥪ⮢ ⨯ string:

               struct string {
                 char* p;
                 int size;   // ࠧ ,   㪠뢠 p

                 string(int size) { p = new char[size=sz]; }
                 ~string() { delete p; }
                 string& operator=(const string&);
               };

               string& string::operator=(const string& a)
               {
                 if (this !=&a) {   // ᭮,  s=s
                    delete p;
                    p = new char[size=a.size];
                    strcpy(p,a.p);
                 }
                 return *this;
               }

         ⠪ । string ।騩 ਬ ன 
   㬠.  ᫥ 讣   f() ஡ 
   ᭮,    稨:

               void f()
               {
                 string s1(10);
                 string s2 = s1;  // 樠,   ᢠ
               }

    ⮫쪮  ꥪ ⨯ string ந ஬
   string::string(int),  㭨⮦ 㤥  ப.  
   ⮬,  짮⥫᪠  ᢠ  ਬ
    樠஢ ꥪ. 筮   㭪
   string::operator(), ⮡  稭 ⮣: 㪠⥫ p
   㤥 ⮣  ।,   砩 祭.
    ࠢ,  樨 ᢠ ।,  
   ࠬ ந樠஢.  樠樨 ⨯ ⮩, 
   ਢ  ⮬ ਬ   ⠪  ।. ⥫쭮,
   ⮡ ࠢ  樠樥 㦭 宦,  ᢮ 㭪:

               struct string {
                 char* p;
                 int size;   // ࠧ ,   㪠뢠 p

                 string(int size) { p = new char[size=sz]; }
                 ~string() { delete p; }
                 string& operator=(const string&);
                 string(const string&);
               };

               string::string(const string& a)
               {
                    p=new char[size=sz];
                    strcpy(p,a.p);
               }


         樠 ꥪ ⨯ X ந室   
   X(const X&).   ⠥ ,  ᢠ 
   樠  ࠧ묨 ﬨ. ᮡ    
   ,  । . ᫨   X  ਢ
   , ਬ, ந騩 ᢮ ꥪ  ᢮
   , ⭥ ᥣ,  ⮬  ॡ  
   㭪権, ⮡  ஢ ꥪ⮢  童:

               class X {
                  // ...
                  X(something);        // , ᮧ騩 ꥪ
                  X(const X&);         //  ஢
                  operator=(const X&); // ᢠ:
                                       // 㤠  ஢
                  ~X();                // , 㤠騩 ꥪ
               };

            ,  室 ஢ ꥪ:
   । ࠬ 㭪樨    祭.  ।
   ࠬ 樠஢ ६, .. ଠ ࠬ
   樠. ⨪ ⮩ 樨 筠 㣨 
   樠樨.  ந室    㭪樥 祭,
     砩  ⠪ 祢.    ᯮ
    ஢:

              string g(string arg)
              {
                return arg;
              }

              main()
              {
                string s = "asdf";
                s = g(s);
              }

   祢, ᫥ 맮 g() 祭 s   "asdf".  㤭
     ࠬ s  祭 s,  ⮣  맢
    ஢  string.  祭   
   祭 s  室  g() 㦥   맮 
   string(const string&).   ࠧ 樠 ६
   ६,  ⥬ ᢠ s.  ⨬樨 ,
     ,   権 ஢  . ⢥,
   ६ ६, ᯮ㥬  ⠪ 楫, 㭨⮦
   騬 ࠧ ஬ string::~string() (. $$R.12.2).
       ᫨   X  ᢠ X::operator=(const X&)
     ஢ X::X(const X&)    ணࠬ⮬,
   騥 樨  ᮧ ࠭஬.  ᮧ
   㭪樨  ஢  童   童  X. ᫨
   童 ਭ  祭,   砥  ᥫ,
   , ,  㦭,  ᮧ 㭪樨 ॢ  ⮥ 
   ⨬쭮 ࠧ來 ஢. ᫨  ᠬ 童
   । 짮⥫᪨ 樨 ஢,   
   뢠 ᮮ⢥騬 ࠧ:

             class Record {
               string name, address, profession;
               // ...
             };

             void f(Record& r1)
             {
               Record r2 = r1;
             }

      ஢  童 ⨯ string  ꥪ r1
    㤥 뢠 string::operator=(const string&).  襬 ࢮ
     業 ਠ ப   童-㪠⥫
     . ⮬ ⠭⭮ ஢  童 
      猪 ୮. ࠭  ।०
     ⠪ .


   7.7 

   ୠ 㭪 operator[]   ꥪ⮢ ᮢ
    樨. ன ࠬ ⮩ 㭪権 () 
    ந ⨯.  , ਬ, ।
   樠⨢ ᨢ.  ⢥ ਬ  ९
   ।  $$2.3.10,  樠⨢ ᨢ ᯮ짮
    让 ணࠬ, 뢠饩 ᫮ 宦 ᫮  䠩.
     ⮣ ᯮ짮 㭪.  । 騩 ⨯
   樠⨢ ᨢ:

             class assoc {
                struct pair {
                   char* name;
                   int val;
                };

                pair* vec;
                int max;
                int free;

                assoc(const assoc&);            // ।頥 ஢
                assoc& operator=(const assoc&); // ।頥 ஢
             public:
                assoc(int);
                int& operator[](const char*);
                void print_all();
              };

    ꥪ assoc ࠭    pair ࠧ஬ max.
    ६ free ࠭  ࢮ ᢮ 
   .
       ⮡ । ஢ ꥪ⮢ assoc, 
   ஢   ᢠ ᠭ  . 
   룫廊 ⠪:

              assoc::assoc(int s)
              {
                max = (s<16) ? 16 : s;
                free = 0;
                vec = new pair[max];
              }

    ॠ樨 ᯮ    䥪⨢  ᪠,
      $$2.3.10.  ⥯, ᫨  ९, ꥪ
   assoc 㢥稢:

              #include <string.h>

              int& assoc::operator[](const char* p)
              /*
                ࠡ⠥  ⢮  ( pair):
                ஢  p, 頥 뫪 
                楫 祭   ,
                ᮧ  , ᫨ p  
              */
              {
                register pair* pp;

                for (pp=&vec[free-1]; vec<=pp; pp-- )
                    if (strcmp(p,pp->name) == 0) return pp->val;
                if (free == max) { //९:  㢥稢
                   pair* nvec = new pair[max*2];
                   for (int i=0; i<max; i++) nvec[i] = vec[i];
                   delete vec;
                   vec = nvec;
                   max = 2*max;
                }

                pp = &vec[free++];
                pp->name = new char[strlen(p)+1];
                strcpy(pp->name,p);
                pp->val = 0;    // 砫쭮 祭 = 0
                return pp->val;
              }

   ᪮ ।⠢ ꥪ assoc   짮⥫, 㦭
       - ࠧ.  ᫥饬 ࠧ
   㤥   । 騩   ⠪ ꥪ.
      ࠭稬 ⮩ 㭪樥 :

              void assoc::print_all()
              {
                for (int i = 0; i<free; i++)
                    cout << vec[i].name << ": " << vec[i].val << '\n';
              }

   ,   ਢ ணࠬ:

              main() //  ᫠ 宦  室
                     // ⮪  ᫮
              {
                const MAX = 256;  //   ᠬ  ᫮
                char buf[MAX];
                assoc vec(512);
                while (cin>>buf) vec[buf]++;
                vec.print_all();
              }

    ணࠬ  ,  ன ਩ 
    ஢࣭.    ஡ ।
    ࠦ $$7.14 [20]. 쭥襥 ࠧ⨥ ⨥ 樠⨢
   ᨢ   $$8.8.
       㭪 operator[]()   童 .  ᫥,
    ⭮ x[y] == y[x]   믮, ᫨
   x ꥪ .  ⭮襭 ⭮, ࠢ
    権  ஥묨 ⨯,   믮 
   짮⥫᪨ ⨯ ($$7.2.2, . ⠪ $$7.9).

   7.8 맮 㭪樨

   맮 㭪樨, ..  ࠦ(ᯨ᮪-ࠦ), 
   ᬠਢ   ,  ன ࠦ 
    ࠭,  ᯨ᮪-ࠦ - ࠢ.  맮
    ॣ㦠   㣨 樨.  㭪樨 operator()()
   ᯨ᮪ 䠪᪨ ࠬ஢   ஢  ⨯
   ᮣ᭮  ࠢ । ࠬ஢. ॣ㧪 樨
   맮   ० ᥣ  ⨯,  묨 
   ⮫쪮  ,  ⠪   ⨯,   権 
   묨  ⮫쪮  祭,   ⠫ 
   設⢥ 砥   뢠.
           ।   樠⨢ ᨢ
   ⨯ assoc.  ⮩ 楫  । ᯥ樠 
   assoc_iterator,  ண 뤠   assoc  ஬
   浪.   室    , ࠭
    assoc, ⮬    ᠭ  friend:

              class assoc {
              friend class assoc_iterator;
                  pair* vec;
                  int max;
                  int free;
              public:
                  assoc(int);
                  int& operator[](const char*);
              };

      । ⠪:

              class assoc_iterator {
                 const assoc* cs;   // ᨢ assoc
                 int i;             // ⥪騩 
              public:
                 assoc_iterator(const assoc& s) { cs = &s; i = 0; }
                 pair* operator()()
                   { return (i<cs->free)? &cs->vec[i++] : 0; }
              };

  ᨢ assoc ꥪ assoc_iterator 㦭 樠஢,   
  饭     ୮ 㭪樨 () 㤥 
  㪠⥫    ( pair)  ⮣ ᨢ.  ⨦
   ᨢ 頥 0:

              main()  //  ᫠ 宦  室
                      // ⮪  ᫮
              {
                const MAX = 256;  //   ᠬ  ᫮
                char buf[MAX];
                assoc vec(512);
                while (cin>>buf) vec[buf]++;
                assoc_iterator next(vec);
                pair* p;
                while ( p = next(vec) )
                    cout << p->name << ": " << p->val << '\n';
              }

            २⢮ । ஬
  㭪権, 騬   :    ᮡ⢥
   ,    ࠭ ଠ  室 樨.
  筮   ,   ६  ࠧ ᪮쪮
  ஢  ⨯.
        筮, ᯮ짮 ꥪ⮢  ।⠢ ஢
  ।⢥   易  ॣ㧪 権. 
  । ᯮ짮 ⨯   ⠪ ﬨ, 
  first(), next()  last(), 㣨  ࠢ ॣ㧪 樨
  ++ ,    , ᯮ㥬  㪠⥫
  (. $$8.8). ஬ ⮣, ୠ 㭪 operator() ⨢
  ᯮ  뤥 ப  樨  ᨢ.
        㭪 operator()   㭪樥-童.

  7.9 ᢥ 饭

   ᢥ 饭  童 ->  ।  㭠
  䨪 .  , ᫨  

             class Ptr {
               // ...
               X* operator->();
             };

  ꥪ  Ptr  ᯮ짮  㯠  童 
  X ⠪,   ⮩ 楫 ᯮ 㪠⥫:

            void f(Ptr p)
            {
              p->m = 7;  // (p.operator->())->m = 7
            }

  ॢ饭 ꥪ p  㪠⥫ p.operator->()    
  童 m,    㪠뢠.   ⮩ 稭 operator->()
   㭠୮ 䨪᭮ 樥. ,    
  ᨭ⠪᪨ 祭, ⠪   童 -० 
   ᫥ -> :

             void g(Ptr p)
             {
                X* q1 = p->;  // ᨭ⠪᪠ 訡
                X* q2 = p.operator->(); // ଠ쭮
             }

       ॣ㧪 樨 -> ० ᥣ ᯮ  ᮧ
  " 㪠⥫", .. ꥪ⮢,   ᯮ짮 
  㪠⥫  ஢  樨   饭
   㪠㥬 ꥪ   . ਬ,  । 
  RecPtr  ࣠樨 㯠  ꥪ⠬  Rec, ࠭ 
  ᪥. ࠬ஬  RecPtr  , ஥ 㤥
  ᯮ짮  ᪠ ꥪ  ᪥.  饭  ꥪ
    㭪樨 RecPtr::operator->()  ९뢠  ᭮
  ,    ࠡ  RecPtr 뢠 
  ꥪ ⭮  .

              class RecPtr {
                 Rec* in_core_address;
                 const char* identifier;
                 // ...
              public:
                 RecPtr(const char* p)
                 : identifier(p) { in_core_address = 0; }
                 ~RecPtr()
                    { write_to_disc(in_core_address,identifier); }
                 Rec* operator->();
              };

              Rec* RecPtr::operator->()
              {
                if (in_core_address == 0)
                    in_core_address = read_from_disc(identifier);
                return in_core_address;
              }

  ᯮ짮   ⠪:

              main(int argc, const char* argv)
              {
                for (int i = argc; i; i--) {
                    RecPtr p(argv[i]);
                    p->update();
                }
              }

   ᠬ , ⨯ RecPtr  ।  蠡 ⨯
  (. $$8),  ⨯  Record 㤥  ࠬ஬. ஬
  ⮣,  ணࠬ 㤥 ᮤঠ ࠡ 訡 
  ⢨  ᪮ 㤥 ࣠  ⮫ ਬ⨢.
          㪠⥫  -> ⭠ ,
  ᯮ騬 *  []. , ᫨ ᠭ

              Y* p;

   믮 ᮮ⭮襭

              p->m == (*p).m == p[0].m

   ᥣ,  । 짮⥫ 権 ⠪ ᮮ⭮襭
   ࠭. ,  -⠪ ⠪ ⭮ ॡ,
    ᯥ:

              class X {
                Y* p;
              public:
                Y* operator->() { return p; }
                Y& operator*() { return *p; }
                Y& operator[](int i) { return p[i]; }
              };

      ᫨  襬  ।    樨,
  ࠧ㬭 㤥 ᯥ ⭮, 筮 ⠪ ,  ࠧ㬭
  ।ᬮ  ⮩ ६ x ண ,  ஬
   樨 ++, += =  +, ⮡ 樨 ++x  x+=1 뫨
   x=x+1.
     ॣ㧪 ->   ॣ㧪 []    ஫ 
  楫   ணࠬ,     ᯥਬ⮬
  ࠤ ⢠.   ⮬,   ணࠬ஢ ⨥
  ᢥ  祢,  ॣ㧪 ->  , אַ
   䥪⨢ ᯮᮡ ।⠢ ⮣   ணࠬ.
   㣠 窠 ७   ->,   ।⢮ 
   ++ ࠭祭,   ਠ  ஢
  (. $$12.2.8  13.9).

  7.10 ६  ६

  ᫨  㬠  " 㪠⥫",  筮 ஡
  ८। 樨 ६ ++  ६ -- , ⮡
    ᮢ  ,   樨  
  ஥ ⨯.   ᮡ ⢥  室, ᫨
  ⠢ 楫  ⨯  㪠⥫  ⨯ " 㪠⥫",
   ண ᥬ⨪ ⠥ ०,   
  ⢨ ᪮ ஫.   ணࠬ  ࠭
  訡:

             void f1(T a)   // ࠤ樮 ᯮ짮
             {
               T v[200];
               T* p = &v[10];
               p--;
               *p = a;   // ਥ堫: `p' ஥  ᨢ,
                         //    㦥
               ++p;
               *p = a;   // ଠ쭮
             }

  ⢥   㪠⥫ p  ꥪ 
  CheckedPtrToT,  ஬ ᢥ 饭  ⮫쪮
   ᫮,   ⢨⥫쭮 㪠뢠  ꥪ. ਬ
  ६  ६  ⠪ 㪠⥫ 㤥  ⮫쪮  ⮬
  砥,  㪠⥫ ஥  ꥪ  ࠭ ᨢ 
   १  権  ꥪ  ࠭ ⮣ 
  ᨢ:

             class CheckedPtrToT {
                // ...
             };

             void f2(T a)  // ਠ  ஫
             {
               T v[200];
               CheckedPtrToT p(&v[0],v,200);
               p--;
               *p = a;  // ᪠ 訡:
                        // `p' 襫  ࠭ ᨢ
               ++p;
               *p = a;  // ଠ쭮
             }

  ६  ६  ⢥묨 ﬨ  ++,
    ᯮ짮  䨪  䨪 樨.
  ⥫쭮,  ।  CheckedPtrToT  
  ।ᬮ ⤥ 㭪樨  䨪  䨪 権
  ६  ६:

             class CheckedPtrToT {
               T* p;
               T* array;
               int size;
             public:
                    // 砫쭮 祭 `p'
                    // 뢠  ᨢ `a' ࠧ `s'
                 CheckedPtrToT(T* p, T* a, int s);
                    // 砫쭮 祭 `p'
                    // 뢠   ꥪ⮬
                 CheckedPtrToT(T* p);

                 T* operator++();     // 䨪᭠
                 T* operator++(int);  // 䨪᭠

                 T* operator--();     // 䨪᭠
                 T* operator--(int);  // 䨪᭠

                 T& operator*();      // 䨪᭠
              };

  ࠬ ⨯ int 㦨 㪠,  㭪 㤥 뢠
   䨪᭮ 樨.  ᠬ   ࠬ 
  ⢥    ᯮ,  㦨 ⮫쪮  ࠧ
  䨪᭮  䨪᭮ 樨. ⮡ ,  
  㭪樨 operator++ ᯮ  䨪᭠ , 筮
  ,  䨪᭮    ⢥ ࠬ,
   ୮    㣨 㭠 䬥᪨  ᪨
  権. ⢥ ࠬ ᯮ ⮫쪮  "ᮡ"
  䨪 権 ++  --.
         CheckedPtrToT ਬ   ⠪:

               void f3(T a)  // ਠ  ஫
               {
                 T v[200];
                 CheckedPtrToT p(&v[0],v,200);
                 p.operator--(1);
                 p.operator*() = a; // ᪠ 訡:
                                    // `p' 襫  ࠭ ᨢ
                 p.operator++();
                 p.operator*() = a; // ଠ쭮
               }

   ࠦ $$7.14 [19] ।  । 
  CheckedPtrToT,  㣨 ࠦ ($$9.10[2]) 
  ८ࠧ   蠡 ⨯,  ஬  ᮮ饭 
  ᪨ 訡 ᯮ ᮡ 樨. ਬ ᯮ짮
  権 ++  --  権    $$8.8.

   7.11 ப 

     ਢ  ᫥ ਠ  string.
     뢠 ᫮ 뫮  ப, ⮡ ஢
   ஢,  ᯮ  ⠭ ⠭ ப C++.

              #include <iostream.h>
              #include <string.h>

              class string {
                 struct srep {
                   char* s;       // 㪠⥫  ப
                   int n;         // 稪 ᫠ 뫮
                   srep() { n = 1; }
                 };
                 srep *p;

              public:
                string(const char *);   // string x = "abc"
                string();               // string x;
                string(const string &); // string x = string ...
                string& operator=(const char *);
                string& operator=(const string &);
                ~string();
                char& operator[](int i);

                friend ostream& operator<<(ostream&, const string&);
                friend istream& operator>>(istream&, string&);

                friend int operator==(const string &x, const char *s)
                  { return strcmp(x.p->s,s) == 0; }

                friend int operator==(const string &x, const string &y)
                  { return strcmp(x.p->s,y.p->s) == 0; }

                friend int operator!=(const string &x, const char *s)
                  { return strcmp(x.p->s,s) != 0; }

                friend int operator!=(const string &x, const string &y)
                  { return strcmp(x.p->s,y.p->s) != 0; }
             };

     ਢ:

             string::string()
             {
               p = new srep;
               p->s = 0;
             }

             string::string(const string& x)
             {
               x.p->n++;
               p = x.p;
             }

             string::string(const char* s)
             {
               p = new srep;
               p->s = new char[ strlen(s)+1 ];
               strcpy(p->s, s);
             }

             string::~string()
             {
               if (--p->n == 0) {
                  delete[]  p->s;
                  delete p;
               }
             }

     ᥣ 樨 ᢠ 宦  .  
   㦭   㤠 ࢮ ࠭, 饣 
    ᢠ:

            string& string::operator=(const char* s)
            {
              if (p->n > 1) {  // ᮥ塞  ன ப
                  p->n--;
                  p = new srep;
              }
              else    // ᢮ ப   祭
                  delete[] p->s;

              p->s = new char[ strlen(s)+1 ];
              strcpy(p->s, s);
              return *this;
            }

            string& string::operator=(const string& x)
            {
              x.p->n++;  //    ``st = st''
              if (--p->n == 0) {
                 delete[] p->s;
                 delete p
              }
              p = x.p;
              return *this;
            }

    뢮 뢠  ᯮ 稪 ᫠ 뫮.
    ᮯ஢     ப ( ந室
     樨 << , ਢ ):

            ostream& operator<<(ostream& s, const string& x)
            {
               return s << x.p->s << " [" << x.p->n << "]\n";
            }

     ந室   ⠭⭮ 㭪樨 
   ᨬ쭮 ப ($$10.3.1):

            istream& operator>>(istream& s, string& x)
            {
               char buf[256];
               s >> buf;   // :  ९ buf
                           // ࠢ쭮 襭 .  $$10.3.1
               x = buf;
               cout << "echo: " << x << '\n';
               return s;
             }

         樨 㦭  㯠  ⤥ ᨬ.
    ஫:

            void error(const char* p)
            {
              cerr << p << '\n';
              exit(1);
            }

           char& string::operator[](int i)
          {
           if (i<0 || strlen(p->s)<i) error("⨬ 祭 ");
             return p->s[i];
          }

       ᭮ ணࠬ   ᪮쪮 ਬ஢ ਬ
   ப 権.   室 ⮪   ப,
    ⥬ ப .  த   ,  
   㤥 㦥 ப done,   ப  
   ᫮,   室 ⮪. ⥬   ப
    ⭮ 浪  ணࠬ 蠥.

           int main()
           {
             string x[100];
             int n;

             cout << "  砫 \n";

             for ( n = 0; cin>>x[n]; n++) {
                 if (n==100) {
                    error("᫨誮  ᫮");
                    return 99;
                 }
                 string y;
                 cout << (y = x[n]);
                 if (y == "done") break;

             }
             cout << "⥯    ᫮  ⭮ 浪 \n";
             for (int i=n-1; 0<=i; i--) cout << x[i];
             return 0;
           }

   7.12   童

    祭  㤨,   饭   
   짮⥫᪮ ⨯ ⮨ ᯮ짮 㭪樨-童,  
   㭪樨-.  㭪樨, ਬ , 
    㠫 㭪樨 ($$R.12), 易  童,   㣨
     롮. ᪮, 뢠 㭪  童, 
      쭮 ,  ⢨ 㣨 
   ᫥ ᯮ짮 㭪樨-童.
        ᬮਬ ⮩  X:

            class X {
               // ...

              X(int);

              int m1();
              int m2() const;

              friend int f1(X&);
              friend int f2(const X&);
              friend int f3(X);
           };

   砫 㪠,  童 X::m1()  X::m2()  뢠 ⮫쪮
    ꥪ⮢  X. ८ࠧ X(int)  㤥 ਬ
    ꥪ,  ண 맢 X::m1()  X::m2():

            void g()
            {
               1.m1();  // 訡: X(1).m1()  ᯮ
               1.m2();  // 訡: X(1).m2()  ᯮ
            }

   쭠 㭪 f1()    ᢮⢮ ($$4.6.3), ᪮
    ࠬ - 뫪  ᯥ䨪樨 const.  㭪ﬨ f2() 
   f3()  :

            void h()
            {
              f1(1);  // 訡: f1(X(1))  ᯮ
              f2(1);  // ଠ쭮: f2(X(1));
              f3(1);  // ଠ쭮: f3(X(1));
            }

       ⥫쭮 ,  ﭨ ꥪ ,
     童  쭮 㭪樥  ࠬ஬-뫪
    ᯥ䨪樨 const. 樨  ᭮묨 ⨯, 
   ॡ  ⢥ ࠭  (=, *, ++  ..),
    짮⥫᪨ ⨯ ⢥ ।  童.
       ⭮, ᫨ ॡ  ८ࠧ ⨯  
   ࠭ ன 樨,  ॠ  㭪 
     童,  쭮 㭪樥   ࠬ ⨯ 뫪
    ᯥ䨪樥 const  뫮 ࠬ.  筮 ⮨
     㭪ﬨ, ॠ騬 樨,   ᭮
   ⨯  ॡ ᮢ  ⢥ ࠭ (+, -, ||  ..).
       ᫨ 樨 ८ࠧ ⨯  ।,  
   ஢ন    㭪樨-童 । 㭪樥-㣮
    ࠬ஬-뫪  . 뢠,  ணࠬ 
    ଠ  맮 ࠢ , 祬 㣠.
   ਬ,   祭 㭪樨 饭  m 
   ࠢ  inv(m), 祬 m.inv(). 筮, ᫨ 㭪
   inv() 頥 ᠬ  m,   頥 ,  m,
   ,  inv()   童.
          ࠢ ᫮  -⠪ ⠭
    㭪樨-童.  ਢ ⠪ .  ࠭஢,
    -  㤥 ।  饭.  
     ࠭஢,  騥    
   ᮡ   ﭨ ꥪ.  맮 㭪樨-童
   ᭮ 뢠 ணࠬ,  ꥪ   , ⮣
      ࠬ஬-뫪   ⮫ 祢. ,
   ࠦ ⨬  㭪樨-童   ⢥
     ࠦ  쭮 㭪樨. 쭠
   㭪  ᯮ짮   ࠬ,  
   㭪樨-童   ᯮ짮 㪠⥫ this. ,
   ᪮  童   묨 ,  筮
   뢠 , 祬   㭪権.

   7.13 ।०

     类 㣮 몮 ।⢮, ॣ㧪 権 
   ᯮ짮 ࠧ㬭  ࠧ㬭.  ⭮, 
   ਤ      ᯮ짮
   ⠪,  ணࠬ 㤥 ᮢ襭 ⨦. ।⠢,
    㤥 ⥫, ᫨  ᢮ ணࠬ  ८।
    + ⠪, ⮡  砫 ⠭. ᠭ 
   堭 ॣ㧪 㤥  ணࠬ  짮⥫ 
   ⠪ . ⮬ ணࠬ    
    権  ᭮묨 ⨯ , ⠪,  int, 
   ᨭ⠪ ࠦ  ਮ 権  .
        ᥩ  ॣ㧪 権   ᯮ짮
    ࠦ ࠤ樮 ᯮ짮 権.   
   맮 㭪樨  ᯮ짮   ,  ࠤ樮
      樥  , ,   権,
    ᪠ ॣ㧪,  祭, ⮡   
    㦭 ⢨.

   7.14 ࠦ

   1. (*2) ।    string. । 
      ⥭樨 +   += ,  "   ப".
        樨  ⥫   ᬮ ।  ⮣
      ?
   2. (*1.5) ।  ப   뤥 ப
        ॣ㧪 ().
   3. (*3) ।  string ⠪ ࠧ, ⮡ 
      뤥 ப  뫮 ਬ   
      ᢠ. 砫  ਠ,  ஬ ப 
      ᢠ ப ⮩  ,  ⥬ ਠ  ࠧ묨
       ப.
   4. (*2) ࠡ⠩  string ⠪ ࠧ, ⮡ ꥪ
       ࠪ⮢  । ࠬ஢  ᢠ 
      祭, .. ⮡   string ஢ ᠬ ।⠢
      ப,   ⮫쪮 ࠢ騥 .
   5. (*3)   string  ।饣 ࠦ ⠪, ⮡
      ப ஢ ⮫쪮  室.  , 
      㦭 ࠭  饥 ।⠢   ப 
       ,      .  ⠩  
      뤥 ப,  ६  ਬ  
        ᢠ.
   6. (*4) ।  string, 騩 ᫥묨 
      । ࠦ ᢮⢠: ꥪ  ࠪ 
      祭, ஢  ⫮ (.. ந室 ⮫쪮
       室)   뤥 ப  ਬ
         ᢠ.
   7. (*2)  ८ࠧ ⨯ ᯮ  ࠦ ᫥饩
      ணࠬ?

             struct X {
               int i;
               X(int);
               operator+(int);
             };

             struct Y {
               int i;
               Y(X);
               operator+(X);
               operator int();
             };

             extern X operator*(X,Y);
             extern int f(X);

             X x = 1;
             Y y = x;
             int i = 2;

             int main()
             {
               i + 10;     y + 10;    y + 10 * y;
               x + y + i;  x * X +i;  f(7);
               f(y);       y + y;     106 + y;
             }

      । X  Y  楫 ⨯.  ணࠬ ⠪, ⮡
        뫮 믮   ⠫ 祭 
      ࠢ ࠦ.
   8. (*2) ।  INT,  㤥 ⥭ ⨯ int.
      ᪠: । 㭪 INT::operator int().
   9. (*1) ।  RINT,  㤥 ⥭ ⨯ int,
       ᪫祭 ⮣,  ⨬묨  ⮫쪮 樨:
      + (㭠  ), - (㭠  ), *, /  %.
      ᪠:   । RINT::operator int().
   10. (*3) ।  LINT,   RINT,  
        ।⠢ 楫  ᯮ짮   64
      ࠧ冷.
   11. (*4) । , ॠ騩 䬥⨪  ந쭮
      筮. ᪠: ਤ ᯮ짮  ⠪, 
          string.
   12. (*2)  ணࠬ,  ன  ப 
      ॣ㧪 㤥  ࠧ. : । 
      ⨯ INT +  -,  ;   ம। 
      int  INT. ஬ ⮣,  ⠭  ᮧ,
      ८। ப  㭪樨,  ᯮ ࠬ
      ⨯ 뫪   騥  㦤 ਨ.
   13. (*3)  襭ﬨ ࠦ [12]  訬 㣮.
      ஡ ,    ணࠬ,  ᪠ . ᫨
       ᤥ  ࠦ,  ⠭ ᭮, 祣  .
   14. (*2) ९ ਬ  ᠬ complex ($$7.3), tiny
      ($$7.3.2)  string ($$7.11),  ᯮ 㦥⢥ 㭪樨.
      ᯮ ⮫쪮 㭪樨-童. ஢  ᨨ 
      ᮢ. ࠢ   ﬨ,   ᯮ
      㦥⢥ 㭪樨.   ࠦ 5.3.
   15. (*2) । ⨯ vec4     ᥫ  饩
      窮. ।   㭪 operator[].  権
      ஢  ᥫ  饩 窮 । 樨:
      +, -, *, /, =, +=, -=, *=  /=.
   16. (*3) ।  mat4     ⮢ ⨯
      vec4. ।   㭪 operator[],  vec4.
      ।  ⮣ ⨯  樨  栬. ।
       mat4 㭪, ந ८ࠧ   楩.
   17. (*2) ।  vector,   vec4,  
      ࠧ     ࠬ 
      vector::vector(int).
   18. (*3) ।  matrix,   mat4,  
      ࠧ୮     ࠬ 
      matrix::matrix(int,int).
   19. (*3)  ।  CheckedPtrToT  $$7.10 
      ஢ . ⮡ । ⮣  뫮 ,
      室 ।,  ࠩ , ⠪ 樨: *, ->,
      =, ++  --.  뤠  訡,  ⢨⥫쭮
       ந 饭  㪠⥫  । 祭.
   20. (*1.5) ९ ਬ  ணࠬ  ᫮  $$7.7
      ⠪, ⮡    뫮 ࠭  ᨬ쭮 
      ᫮.

