Previous section   Next section

Imperfect C++ Practical Solutions for Real-Life Programming
By Matthew Wilson
Table of Contents
Chapter 29.  Arithmetic Types


29.6. Arithmetic Operators

Just as with assignment, we can rely on conversion construction to make our task here very simple. First, we need to define the member composite assignment operators [Stro1997]:

Listing 29.4.


class UInteger64


{


  . . .


  UInteger64 &operator +=(UInteger64 const &rhs)


  {


    get_union_().i += rhs.get_union_().i;


    return *this;


  }


  UInteger64 &operator -=(UInteger64 const &rhs);


  UInteger64 &operator *=(UInteger64 const &rhs);


  UInteger64 &operator /=(UInteger64 const &rhs);


  UInteger64 &operator %=(UInteger64 const &rhs);


  UInteger64 &operator ^=(UInteger64 const &rhs);


  . . .



The binary operators are then provided as nonmember functions, implemented in terms of the public interface of the class:



UInteger64 operator +( UInteger64 const &lhs


                     , UInteger64 const &rhs)


{


  return UInteger64(lhs) += rhs;


}




      Previous section   Next section