A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FOverload%2FPlus</id>
		<title>C++/Overload/Plus - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FOverload%2FPlus"/>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/Overload/Plus&amp;action=history"/>
		<updated>2026-04-10T17:26:01Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B/Overload/Plus&amp;diff=1991&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/Overload/Plus&amp;diff=1991&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B/Overload/Plus&amp;diff=1992&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/Overload/Plus&amp;diff=1992&amp;oldid=prev"/>
				<updated>2010-05-25T10:28:22Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==additional meanings for the + and = operations==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;  &lt;br /&gt;
#include &amp;lt;string.h&amp;gt;  &lt;br /&gt;
using namespace std;&lt;br /&gt;
class str_type {  &lt;br /&gt;
  char string[80];  &lt;br /&gt;
public:  &lt;br /&gt;
  str_type(char *str = &amp;quot;\0&amp;quot;) { strcpy(string, str); }  &lt;br /&gt;
     &lt;br /&gt;
  str_type operator+(str_type str);  &lt;br /&gt;
  str_type operator+(char *str);  &lt;br /&gt;
     &lt;br /&gt;
  str_type operator=(str_type str);  &lt;br /&gt;
  str_type operator=(char *str);  &lt;br /&gt;
     &lt;br /&gt;
  void show_str(void) { cout &amp;lt;&amp;lt; string; }  &lt;br /&gt;
} ;  &lt;br /&gt;
     &lt;br /&gt;
str_type str_type::operator+(str_type str) {  &lt;br /&gt;
  str_type temp;  &lt;br /&gt;
     &lt;br /&gt;
  strcpy(temp.string, string);  &lt;br /&gt;
  strcat(temp.string, str.string);  &lt;br /&gt;
  return temp;  &lt;br /&gt;
}  &lt;br /&gt;
     &lt;br /&gt;
str_type str_type::operator=(str_type str) {  &lt;br /&gt;
  strcpy(string, str.string);  &lt;br /&gt;
  return *this;  &lt;br /&gt;
}  &lt;br /&gt;
     &lt;br /&gt;
str_type str_type::operator=(char *str)  &lt;br /&gt;
{  &lt;br /&gt;
  str_type temp;  &lt;br /&gt;
     &lt;br /&gt;
  strcpy(string, str);  &lt;br /&gt;
  strcpy(temp.string, string);  &lt;br /&gt;
  return temp;  &lt;br /&gt;
}  &lt;br /&gt;
     &lt;br /&gt;
str_type str_type::operator+(char *str)  &lt;br /&gt;
{  &lt;br /&gt;
  str_type temp;  &lt;br /&gt;
     &lt;br /&gt;
  strcpy(temp.string, string);  &lt;br /&gt;
  strcat(temp.string, str);  &lt;br /&gt;
  return temp;  &lt;br /&gt;
}  &lt;br /&gt;
     &lt;br /&gt;
main(void)  &lt;br /&gt;
{  &lt;br /&gt;
  str_type a(&amp;quot;Hello &amp;quot;), b(&amp;quot;There&amp;quot;), c;  &lt;br /&gt;
     &lt;br /&gt;
  c = a + b;  &lt;br /&gt;
     &lt;br /&gt;
  c.show_str();  &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;  &lt;br /&gt;
     &lt;br /&gt;
  a = &amp;quot;to program in because&amp;quot;;  &lt;br /&gt;
  a.show_str();  &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;  &lt;br /&gt;
     &lt;br /&gt;
  b = c = &amp;quot;C++ is fun&amp;quot;;  &lt;br /&gt;
     &lt;br /&gt;
  c = c+&amp;quot; &amp;quot;+a+&amp;quot; &amp;quot;+b;  &lt;br /&gt;
  c.show_str();  &lt;br /&gt;
     &lt;br /&gt;
  return 0;  &lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Define operator +(plus) and cast to double operator==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
class Power {&lt;br /&gt;
   double b;&lt;br /&gt;
   int e;&lt;br /&gt;
   double val;&lt;br /&gt;
 public:&lt;br /&gt;
   Power(double base, int exp);&lt;br /&gt;
   Power operator+(Power obj) {&lt;br /&gt;
      double base;&lt;br /&gt;
      int exp; &lt;br /&gt;
      base = b + obj.b;&lt;br /&gt;
      exp = e + obj.e;&lt;br /&gt;
      Power temp(base, exp);&lt;br /&gt;
      return temp;&lt;br /&gt;
   }&lt;br /&gt;
   operator double(void) {return val;}     &lt;br /&gt;
};&lt;br /&gt;
Power::Power(double base, int exp){&lt;br /&gt;
   b = base;&lt;br /&gt;
   e = exp;&lt;br /&gt;
   val = 1;&lt;br /&gt;
   if (exp!=0)&lt;br /&gt;
      while(exp-- &amp;gt; 0)&lt;br /&gt;
         val *= b;&lt;br /&gt;
}&lt;br /&gt;
int main(void){&lt;br /&gt;
   Power pwr1(4.0, 2);&lt;br /&gt;
   double doub1;&lt;br /&gt;
   doub1 = pwr1;                &lt;br /&gt;
   cout &amp;lt;&amp;lt; (doub1 + 100.2) &amp;lt;&amp;lt; endl;&lt;br /&gt;
   Power pwr2(3.3, 3), pwr3(0,0);&lt;br /&gt;
   pwr3 = pwr1 + pwr2;          &lt;br /&gt;
   doub1 = pwr3;                &lt;br /&gt;
   cout &amp;lt;&amp;lt; doub1;&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Friendly operator+==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
class String{&lt;br /&gt;
   public:&lt;br /&gt;
      String();&lt;br /&gt;
      String(const char *const);&lt;br /&gt;
      String(const String &amp;amp;);&lt;br /&gt;
      ~String();&lt;br /&gt;
      char &amp;amp; operator[](int offset);&lt;br /&gt;
      char operator[](int offset) const;&lt;br /&gt;
      String operator+(const String&amp;amp;);&lt;br /&gt;
      friend String operator+(const String&amp;amp;, const String&amp;amp;);&lt;br /&gt;
      void operator+=(const String&amp;amp;);&lt;br /&gt;
      String &amp;amp; operator= (const String &amp;amp;);&lt;br /&gt;
      int GetLen()const { return itsLen; }&lt;br /&gt;
      const char * GetString() const { return itsString; }&lt;br /&gt;
   private:&lt;br /&gt;
      String (int);&lt;br /&gt;
      char * itsString;&lt;br /&gt;
      unsigned short itsLen;&lt;br /&gt;
};&lt;br /&gt;
String::String()&lt;br /&gt;
{&lt;br /&gt;
   itsString = new char[1];&lt;br /&gt;
   itsString[0] = &amp;quot;\0&amp;quot;;&lt;br /&gt;
   itsLen=0;&lt;br /&gt;
}&lt;br /&gt;
String::String(int len)&lt;br /&gt;
{&lt;br /&gt;
   itsString = new char[len+1];&lt;br /&gt;
   for (int i = 0; i&amp;lt;=len; i++)&lt;br /&gt;
      itsString[i] = &amp;quot;\0&amp;quot;;&lt;br /&gt;
   itsLen=len;&lt;br /&gt;
}&lt;br /&gt;
String::String(const char * const cString)&lt;br /&gt;
{&lt;br /&gt;
   itsLen = strlen(cString);&lt;br /&gt;
   itsString = new char[itsLen+1];&lt;br /&gt;
   for (int i = 0; i&amp;lt;itsLen; i++)&lt;br /&gt;
      itsString[i] = cString[i];&lt;br /&gt;
   itsString[itsLen]=&amp;quot;\0&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
String::String (const String &amp;amp; rhs)&lt;br /&gt;
{&lt;br /&gt;
   itsLen=rhs.GetLen();&lt;br /&gt;
   itsString = new char[itsLen+1];&lt;br /&gt;
   for (int i = 0; i&amp;lt;itsLen;i++)&lt;br /&gt;
      itsString[i] = rhs[i];&lt;br /&gt;
   itsString[itsLen] = &amp;quot;\0&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
String::~String ()&lt;br /&gt;
{&lt;br /&gt;
   delete [] itsString;&lt;br /&gt;
   itsLen = 0;&lt;br /&gt;
}&lt;br /&gt;
String&amp;amp; String::operator=(const String &amp;amp; rhs)&lt;br /&gt;
{&lt;br /&gt;
   if (this == &amp;amp;rhs)&lt;br /&gt;
      return *this;&lt;br /&gt;
   delete [] itsString;&lt;br /&gt;
   itsLen=rhs.GetLen();&lt;br /&gt;
   itsString = new char[itsLen+1];&lt;br /&gt;
   for (int i = 0; i&amp;lt;itsLen;i++)&lt;br /&gt;
      itsString[i] = rhs[i];&lt;br /&gt;
    itsString[itsLen] = &amp;quot;\0&amp;quot;;&lt;br /&gt;
    return *this;&lt;br /&gt;
}&lt;br /&gt;
char &amp;amp; String::operator[](int offset)&lt;br /&gt;
{&lt;br /&gt;
   if (offset &amp;gt; itsLen)&lt;br /&gt;
      return itsString[itsLen-1];&lt;br /&gt;
   else&lt;br /&gt;
      return itsString[offset];&lt;br /&gt;
}&lt;br /&gt;
char String::operator[](int offset) const&lt;br /&gt;
{&lt;br /&gt;
   if (offset &amp;gt; itsLen)&lt;br /&gt;
      return itsString[itsLen-1];&lt;br /&gt;
   else&lt;br /&gt;
      return itsString[offset];&lt;br /&gt;
}&lt;br /&gt;
String String::operator+(const String&amp;amp; rhs)&lt;br /&gt;
{&lt;br /&gt;
   int  totalLen = itsLen + rhs.GetLen();&lt;br /&gt;
   String temp(totalLen);&lt;br /&gt;
   int i, j;&lt;br /&gt;
   for (i = 0; i&amp;lt;itsLen; i++)&lt;br /&gt;
      temp[i] = itsString[i];&lt;br /&gt;
   for (j = 0, i = itsLen; j&amp;lt;rhs.GetLen(); j++, i++)&lt;br /&gt;
      temp[i] = rhs[j];&lt;br /&gt;
   temp[totalLen]=&amp;quot;\0&amp;quot;;&lt;br /&gt;
   return temp;&lt;br /&gt;
}&lt;br /&gt;
String operator+(const String&amp;amp; lhs, const String&amp;amp; rhs)&lt;br /&gt;
{&lt;br /&gt;
   int  totalLen = lhs.GetLen() + rhs.GetLen();&lt;br /&gt;
   String temp(totalLen);&lt;br /&gt;
   int i, j;&lt;br /&gt;
   for (i = 0; i&amp;lt;lhs.GetLen(); i++)&lt;br /&gt;
      temp[i] = lhs[i];&lt;br /&gt;
   for (j = 0, i = lhs.GetLen(); j&amp;lt;rhs.GetLen(); j++, i++)&lt;br /&gt;
      temp[i] = rhs[j];&lt;br /&gt;
   temp[totalLen]=&amp;quot;\0&amp;quot;;&lt;br /&gt;
   return temp;&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   String s1(&amp;quot;String One &amp;quot;);&lt;br /&gt;
   String s2(&amp;quot;String Two &amp;quot;);&lt;br /&gt;
   char *c1 = { &amp;quot;C-String One &amp;quot; } ;&lt;br /&gt;
   String s3;&lt;br /&gt;
   String s4;&lt;br /&gt;
   String s5;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;s1: &amp;quot; &amp;lt;&amp;lt; s1.GetString() &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;s2: &amp;quot; &amp;lt;&amp;lt; s2.GetString() &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;c1: &amp;quot; &amp;lt;&amp;lt; c1 &amp;lt;&amp;lt; endl;&lt;br /&gt;
   s3 = s1 + s2;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;s3: &amp;quot; &amp;lt;&amp;lt; s3.GetString() &amp;lt;&amp;lt; endl;&lt;br /&gt;
   s4 = s1 + c1;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;s4: &amp;quot; &amp;lt;&amp;lt; s4.GetString() &amp;lt;&amp;lt; endl;&lt;br /&gt;
   s5 = c1 + s2;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;s5: &amp;quot; &amp;lt;&amp;lt; s5.GetString() &amp;lt;&amp;lt; endl;&lt;br /&gt;
 return 0;&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==friend overloaded + operator==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;  &lt;br /&gt;
using namespace std;  &lt;br /&gt;
class Distance{  &lt;br /&gt;
   private:  &lt;br /&gt;
      int feet;  &lt;br /&gt;
      float inches;  &lt;br /&gt;
   public:  &lt;br /&gt;
      Distance(){ &lt;br /&gt;
         feet = 0; &lt;br /&gt;
         inches = 0.0; &lt;br /&gt;
      }  &lt;br /&gt;
      Distance( float fltfeet ){                        &lt;br /&gt;
         feet = int(fltfeet);     &lt;br /&gt;
         inches = 12*(fltfeet-feet);&lt;br /&gt;
      }  &lt;br /&gt;
      Distance(int ft, float in){ &lt;br /&gt;
         feet = ft; &lt;br /&gt;
         inches = in; &lt;br /&gt;
      }  &lt;br /&gt;
      void showdist(){ &lt;br /&gt;
         cout &amp;lt;&amp;lt; feet &amp;lt;&amp;lt; &amp;quot;\&amp;quot;-&amp;quot; &amp;lt;&amp;lt; inches &amp;lt;&amp;lt; &amp;quot;\&amp;quot;&amp;quot;; &lt;br /&gt;
      }  &lt;br /&gt;
      friend Distance operator + (Distance, Distance); &lt;br /&gt;
};&lt;br /&gt;
Distance operator + (Distance d1, Distance d2){  &lt;br /&gt;
   int f = d1.feet + d2.feet;        &lt;br /&gt;
   float i = d1.inches + d2.inches;  &lt;br /&gt;
   if(i &amp;gt;= 12.0){ &lt;br /&gt;
      i -= 12.0; f++;  &lt;br /&gt;
   }        &lt;br /&gt;
   return Distance(f,i);          &lt;br /&gt;
}  &lt;br /&gt;
int main(){  &lt;br /&gt;
   Distance d1 = 2.5;&lt;br /&gt;
   Distance d2 = 1.25;&lt;br /&gt;
   Distance d3;  &lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;\nd1 = &amp;quot;; &lt;br /&gt;
   d1.showdist();  &lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;\nd2 = &amp;quot;; &lt;br /&gt;
   d2.showdist();  &lt;br /&gt;
  &lt;br /&gt;
   d3 = d1 + 10.0;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;\nd3 = &amp;quot;; d3.showdist();  &lt;br /&gt;
   d3 = 10.0 + d1;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;\nd3 = &amp;quot;; d3.showdist();  &lt;br /&gt;
   cout &amp;lt;&amp;lt; endl;  &lt;br /&gt;
   return 0;  &lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==+ is overloaded for three_d + three_d and for three_d + int.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
class three_d {&lt;br /&gt;
  int x, y, z;&lt;br /&gt;
public:&lt;br /&gt;
  three_d() { x = y = z = 0; }&lt;br /&gt;
  three_d(int i, int j, int k) { x = i; y = j; z = k; }&lt;br /&gt;
  // Add two three_d objects together.&lt;br /&gt;
  three_d operator+(three_d rh_op);&lt;br /&gt;
  // Add an integer to a three_d object.&lt;br /&gt;
  three_d operator+(int rh_op);&lt;br /&gt;
  // Subtract two three_d objects.&lt;br /&gt;
  three_d operator-(three_d rh_op);&lt;br /&gt;
  // Overload assignment.&lt;br /&gt;
  three_d operator=(three_d rh_op);&lt;br /&gt;
  // Overload ==.&lt;br /&gt;
  bool operator==(three_d rh_op);&lt;br /&gt;
  // Overload - for unary operation.&lt;br /&gt;
  three_d operator-();&lt;br /&gt;
  // Let the overloaded inserter be a friend.&lt;br /&gt;
  friend ostream &amp;amp;operator&amp;lt;&amp;lt;(ostream &amp;amp;strm, three_d op);&lt;br /&gt;
  // Let the overloaded + be a friend.&lt;br /&gt;
  friend three_d operator+(int lh_op, three_d rh_op);&lt;br /&gt;
};&lt;br /&gt;
// Overload binary + so that corresponding coordinates are added.&lt;br /&gt;
three_d three_d::operator+(three_d rh_op)&lt;br /&gt;
{&lt;br /&gt;
  three_d temp;&lt;br /&gt;
  temp.x = x + rh_op.x;&lt;br /&gt;
  temp.y = y + rh_op.y;&lt;br /&gt;
  temp.z = z + rh_op.z;&lt;br /&gt;
  return temp;&lt;br /&gt;
}&lt;br /&gt;
// Overload binary + so that an integer can be added to a three_d object.&lt;br /&gt;
three_d three_d::operator+(int rh_op)&lt;br /&gt;
{&lt;br /&gt;
  three_d temp;&lt;br /&gt;
  temp.x = x + rh_op;&lt;br /&gt;
  temp.y = y + rh_op;&lt;br /&gt;
  temp.z = z + rh_op;&lt;br /&gt;
  return temp;&lt;br /&gt;
}&lt;br /&gt;
// Overload binary - so that corresponding coordinates are subtracted.&lt;br /&gt;
three_d three_d::operator-(three_d rh_op)&lt;br /&gt;
{&lt;br /&gt;
  three_d temp;&lt;br /&gt;
  temp.x = x - rh_op.x;&lt;br /&gt;
  temp.y = y - rh_op.y;&lt;br /&gt;
  temp.z = z - rh_op.z;&lt;br /&gt;
  return temp;&lt;br /&gt;
}&lt;br /&gt;
// Overload unary - so that it negates the coordinates.&lt;br /&gt;
three_d three_d::operator-()&lt;br /&gt;
{&lt;br /&gt;
  three_d temp;&lt;br /&gt;
  temp.x = -x;&lt;br /&gt;
  temp.y = -y;&lt;br /&gt;
  temp.z = -z;&lt;br /&gt;
  return temp;&lt;br /&gt;
}&lt;br /&gt;
// Overload assignment for three_d.&lt;br /&gt;
three_d three_d::operator=(three_d rh_op)&lt;br /&gt;
{&lt;br /&gt;
  x = rh_op.x;&lt;br /&gt;
  y = rh_op.y;&lt;br /&gt;
  z = rh_op.z;&lt;br /&gt;
  return *this;&lt;br /&gt;
}&lt;br /&gt;
// Overload == for a three_d object.&lt;br /&gt;
bool three_d::operator==(three_d rh_op)&lt;br /&gt;
{&lt;br /&gt;
  if( (x == rh_op.x) &amp;amp;&amp;amp; (y == rh_op.y) &amp;amp;&amp;amp; (z == rh_op.z) )&lt;br /&gt;
    return true;&lt;br /&gt;
  return false;&lt;br /&gt;
}&lt;br /&gt;
// These are non-member operator functions.&lt;br /&gt;
//&lt;br /&gt;
// Overload &amp;lt;&amp;lt; as a custom inserter for three_d objects.&lt;br /&gt;
ostream &amp;amp;operator&amp;lt;&amp;lt;(ostream &amp;amp;strm, three_d op) {&lt;br /&gt;
  strm &amp;lt;&amp;lt; op.x &amp;lt;&amp;lt; &amp;quot;, &amp;quot; &amp;lt;&amp;lt; op.y &amp;lt;&amp;lt; &amp;quot;, &amp;quot; &amp;lt;&amp;lt; op.z &amp;lt;&amp;lt; endl;&lt;br /&gt;
  return strm;&lt;br /&gt;
}&lt;br /&gt;
// Overload + for int + obj.&lt;br /&gt;
three_d operator+(int lh_op, three_d rh_op) {&lt;br /&gt;
  three_d temp;&lt;br /&gt;
  temp.x = lh_op + rh_op.x;&lt;br /&gt;
  temp.y = lh_op + rh_op.y;&lt;br /&gt;
  temp.z = lh_op + rh_op.z;&lt;br /&gt;
  return temp;&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  three_d objA(1, 2, 3), objB(10, 10, 10), objC;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;This is objA: &amp;quot; &amp;lt;&amp;lt; objA;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;This is objB: &amp;quot; &amp;lt;&amp;lt; objB;&lt;br /&gt;
  // Obtain the negation of objA.&lt;br /&gt;
  objC = -objA;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;This is -objA: &amp;quot; &amp;lt;&amp;lt; objC;&lt;br /&gt;
  // Add objA and objB together.&lt;br /&gt;
  objC = objA + objB;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;objA + objB: &amp;quot; &amp;lt;&amp;lt; objC;&lt;br /&gt;
  // Subtract objB from objA.&lt;br /&gt;
  objC = objA - objB;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;objA - objB: &amp;quot; &amp;lt;&amp;lt; objC;&lt;br /&gt;
  // Add obj + int.&lt;br /&gt;
  objC = objA + 10;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;objA + 10: &amp;quot; &amp;lt;&amp;lt; objC;&lt;br /&gt;
  // Add int + obj.&lt;br /&gt;
  objC = 100 + objA;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;100 + objA: &amp;quot; &amp;lt;&amp;lt; objC;&lt;br /&gt;
  // Compare two objects.&lt;br /&gt;
  if(objA == objB) cout &amp;lt;&amp;lt; &amp;quot;objA is equal to objB.\n&amp;quot;;&lt;br /&gt;
  else cout &amp;lt;&amp;lt; &amp;quot;objA is not equal to objB.\n&amp;quot;;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==overloaded &amp;quot;+&amp;quot; operator adds two Distances==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
class Distance&lt;br /&gt;
{&lt;br /&gt;
   private:&lt;br /&gt;
      int feet;&lt;br /&gt;
      float inches;&lt;br /&gt;
   public:&lt;br /&gt;
      Distance() : feet(0), inches(0.0){  }&lt;br /&gt;
      Distance(int ft, float in) : feet(ft), inches(in)  {  }&lt;br /&gt;
      void getdist(){&lt;br /&gt;
         cout &amp;lt;&amp;lt; &amp;quot;\nEnter feet: &amp;quot;;  cin &amp;gt;&amp;gt; feet;&lt;br /&gt;
         cout &amp;lt;&amp;lt; &amp;quot;Enter inches: &amp;quot;;  cin &amp;gt;&amp;gt; inches;&lt;br /&gt;
      }&lt;br /&gt;
      void showdist() const { cout &amp;lt;&amp;lt; feet &amp;lt;&amp;lt; &amp;quot;\&amp;quot;-&amp;quot; &amp;lt;&amp;lt; inches &amp;lt;&amp;lt; &amp;quot;\&amp;quot;&amp;quot;; }&lt;br /&gt;
      Distance operator + ( Distance ) const;&lt;br /&gt;
};&lt;br /&gt;
Distance Distance::operator + (Distance d2) const{&lt;br /&gt;
   int f = feet + d2.feet;&lt;br /&gt;
   float i = inches + d2.inches;&lt;br /&gt;
   if(i &amp;gt;= 12.0){&lt;br /&gt;
      i -= 12.0;&lt;br /&gt;
      f++;&lt;br /&gt;
   }&lt;br /&gt;
   return Distance(f,i);&lt;br /&gt;
}&lt;br /&gt;
int main()  {&lt;br /&gt;
   Distance dist1, dist3, dist4;&lt;br /&gt;
   dist1.getdist();&lt;br /&gt;
   Distance dist2(11, 6.25);&lt;br /&gt;
   dist3 = dist1 + dist2;&lt;br /&gt;
   dist4 = dist1 + dist2 + dist3;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;dist1 = &amp;quot;;  dist1.showdist(); cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;dist2 = &amp;quot;;  dist2.showdist(); cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;dist3 = &amp;quot;;  dist3.showdist(); cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;dist4 = &amp;quot;;  dist4.showdist(); cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
   return 0;&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==overloaded &amp;quot;+&amp;quot; operator concatenates strings==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
class String{&lt;br /&gt;
   private:&lt;br /&gt;
      enum { SZ=80 };&lt;br /&gt;
      char str[SZ];&lt;br /&gt;
   public:&lt;br /&gt;
      String() { strcpy(str, &amp;quot;&amp;quot;); }&lt;br /&gt;
      String( char s[] ) { strcpy(str, s); }&lt;br /&gt;
      void display() const { cout &amp;lt;&amp;lt; str; }&lt;br /&gt;
      String operator + (String ss) const {&lt;br /&gt;
         String temp;&lt;br /&gt;
         if( strlen(str) + strlen(ss.str) &amp;lt; SZ ){&lt;br /&gt;
            strcpy(temp.str, str);&lt;br /&gt;
            strcat(temp.str, ss.str);&lt;br /&gt;
         }else{&lt;br /&gt;
            cout &amp;lt;&amp;lt; &amp;quot;\nString overflow&amp;quot;; exit(1);&lt;br /&gt;
         }&lt;br /&gt;
         return temp;&lt;br /&gt;
      }&lt;br /&gt;
};&lt;br /&gt;
int main(){&lt;br /&gt;
   String s1 = &amp;quot;aaa &amp;quot;;&lt;br /&gt;
   String s2 = &amp;quot;bbb&amp;quot;;&lt;br /&gt;
   String s3;&lt;br /&gt;
   s1.display();&lt;br /&gt;
   s2.display();&lt;br /&gt;
   s3.display();&lt;br /&gt;
   s3 = s1 + s2;&lt;br /&gt;
   s3.display();&lt;br /&gt;
   return 0;&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Overload + for &amp;quot;ob + int&amp;quot; as well as &amp;quot;ob + ob&amp;quot;.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
class MyClass {&lt;br /&gt;
  int x, y; &lt;br /&gt;
public:&lt;br /&gt;
  MyClass() { &lt;br /&gt;
     x=0; &lt;br /&gt;
     y=0; &lt;br /&gt;
  }&lt;br /&gt;
  MyClass(int i, int j) { &lt;br /&gt;
     x=i; &lt;br /&gt;
     y=j; &lt;br /&gt;
  }&lt;br /&gt;
  void getXY(int &amp;amp;i, int &amp;amp;j) { &lt;br /&gt;
     i=x; &lt;br /&gt;
     j=y; &lt;br /&gt;
  }&lt;br /&gt;
  MyClass operator+(MyClass object2); // ob + ob&lt;br /&gt;
  MyClass operator+(int i);         // ob + int&lt;br /&gt;
};&lt;br /&gt;
// Overload + relative to MyClass class.&lt;br /&gt;
MyClass MyClass::operator+(MyClass object2)&lt;br /&gt;
{&lt;br /&gt;
  MyClass temp;&lt;br /&gt;
  temp.x = x + object2.x;&lt;br /&gt;
  temp.y = y + object2.y;&lt;br /&gt;
  return temp;&lt;br /&gt;
}&lt;br /&gt;
// Overload + for ob + int&lt;br /&gt;
MyClass MyClass::operator+(int i)&lt;br /&gt;
{&lt;br /&gt;
  MyClass temp;&lt;br /&gt;
  temp.x = x + i;&lt;br /&gt;
  temp.y = y + i;&lt;br /&gt;
  return temp;&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  MyClass object1(10, 10), object2(5, 3), object3;&lt;br /&gt;
  int x, y;&lt;br /&gt;
  object3 = object1 + object2;                // add two objects - this calls operator+(MyClass)&lt;br /&gt;
  object3.getXY(x, y);&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;(object1+object2) X: &amp;quot; &amp;lt;&amp;lt; x &amp;lt;&amp;lt; &amp;quot;, Y: &amp;quot; &amp;lt;&amp;lt; y &amp;lt;&amp;lt; endl;&lt;br /&gt;
  object3 = object1 + 100;               // add object + int - this call  operator+(int)&lt;br /&gt;
  object3.getXY(x, y);&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;(object1+100) X: &amp;quot; &amp;lt;&amp;lt; x &amp;lt;&amp;lt; &amp;quot;, Y: &amp;quot; &amp;lt;&amp;lt; y &amp;lt;&amp;lt; endl;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Overloading the + (or any other binary operator) using a friend allows a built-in type to occur on the left or right side of the operator.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;  &lt;br /&gt;
using namespace std;&lt;br /&gt;
class MyClass {  &lt;br /&gt;
public:  &lt;br /&gt;
  int count;  &lt;br /&gt;
  MyClass operator=(int i);  &lt;br /&gt;
  friend MyClass operator+(MyClass ob, int i);  &lt;br /&gt;
  friend MyClass operator+(int i, MyClass ob);  &lt;br /&gt;
};  &lt;br /&gt;
     &lt;br /&gt;
MyClass MyClass::operator=(int i)  &lt;br /&gt;
{  &lt;br /&gt;
  count = i;  &lt;br /&gt;
  return *this;  &lt;br /&gt;
}  &lt;br /&gt;
     &lt;br /&gt;
// This handles ob + int.  &lt;br /&gt;
MyClass operator+(MyClass ob, int i)  &lt;br /&gt;
{  &lt;br /&gt;
  MyClass temp;  &lt;br /&gt;
     &lt;br /&gt;
  temp.count = ob.count + i;  &lt;br /&gt;
  return temp;  &lt;br /&gt;
}  &lt;br /&gt;
     &lt;br /&gt;
// This handles int + ob.  &lt;br /&gt;
MyClass operator+(int i, MyClass ob)  &lt;br /&gt;
{  &lt;br /&gt;
  MyClass temp;  &lt;br /&gt;
     &lt;br /&gt;
  temp.count = ob.count + i;  &lt;br /&gt;
  return temp;  &lt;br /&gt;
}  &lt;br /&gt;
     &lt;br /&gt;
main(void)  &lt;br /&gt;
{  &lt;br /&gt;
  MyClass obj;  &lt;br /&gt;
  obj = 10;  &lt;br /&gt;
  cout &amp;lt;&amp;lt; obj.count &amp;lt;&amp;lt; &amp;quot; &amp;quot;; &lt;br /&gt;
     &lt;br /&gt;
  obj = 10 + obj; &lt;br /&gt;
  cout &amp;lt;&amp;lt; obj.count &amp;lt;&amp;lt; &amp;quot; &amp;quot;; &lt;br /&gt;
     &lt;br /&gt;
  obj = obj + 12; &lt;br /&gt;
  cout &amp;lt;&amp;lt; obj.count;&lt;br /&gt;
     &lt;br /&gt;
  return 0;  &lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==overload the &amp;quot;+&amp;quot; operator so that several angles, in the format degrees minutes seconds, can be added directly.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int totaldegrees, totalminutes, totalseconds;&lt;br /&gt;
class angle_value {&lt;br /&gt;
 int degrees, minutes, seconds;&lt;br /&gt;
 &lt;br /&gt;
 public:&lt;br /&gt;
 angle_value() {degrees=0,minutes=0, seconds=0;}  // constructor&lt;br /&gt;
 angle_value(char *);&lt;br /&gt;
 angle_value operator +(angle_value);&lt;br /&gt;
};&lt;br /&gt;
angle_value::angle_value(char *angle_sum)&lt;br /&gt;
{&lt;br /&gt;
 degrees=atoi(strtok(angle_sum,&amp;quot;d&amp;quot;));&lt;br /&gt;
 minutes=atoi(strtok(0,&amp;quot;m&amp;quot;));&lt;br /&gt;
 seconds=atoi(strtok(0,&amp;quot;s&amp;quot;));&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
angle_value angle_value::operator+(angle_value angle_sum){&lt;br /&gt;
 angle_value ang;&lt;br /&gt;
 ang.seconds=(seconds+angle_sum.seconds)%60;&lt;br /&gt;
 ang.minutes=((seconds+angle_sum.seconds)/60+ minutes+angle_sum.minutes)%60;&lt;br /&gt;
 ang.degrees=((seconds+angle_sum.seconds)/60+ minutes+angle_sum.minutes)/60;&lt;br /&gt;
 ang.degrees+=degrees+angle_sum.degrees;&lt;br /&gt;
 totaldegrees=ang.degrees;&lt;br /&gt;
 totalminutes=ang.minutes;&lt;br /&gt;
 totalseconds=ang.seconds;&lt;br /&gt;
 return ang;&lt;br /&gt;
}&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
 char str1[] = &amp;quot;37d 15m 56s&amp;quot;;&lt;br /&gt;
 angle_value angle1(str1);   &lt;br /&gt;
 &lt;br /&gt;
 char str2[] = &amp;quot;10d 44m 44s&amp;quot;;&lt;br /&gt;
 angle_value angle2(str2);&lt;br /&gt;
 &lt;br /&gt;
 char str3[] = &amp;quot;75d 17m 59s&amp;quot;;&lt;br /&gt;
 angle_value angle3(str3);&lt;br /&gt;
  &lt;br /&gt;
   char str4[] = &amp;quot;130d 32m 54s&amp;quot;;&lt;br /&gt;
 angle_value angle4(str4);&lt;br /&gt;
 &lt;br /&gt;
 angle_value sum_of_angles;&lt;br /&gt;
 sum_of_angles=angle1+angle2+angle3+angle4;&lt;br /&gt;
 cout &amp;lt;&amp;lt; &amp;quot;The sum of the angles is &amp;quot; &amp;lt;&amp;lt; totaldegrees &amp;lt;&amp;lt; &amp;quot;d &amp;quot;&lt;br /&gt;
      &amp;lt;&amp;lt; totalminutes &amp;lt;&amp;lt; &amp;quot;m &amp;quot; &amp;lt;&amp;lt; totalseconds &amp;lt;&amp;lt; &amp;quot;s&amp;quot;  &amp;lt;&amp;lt; endl;&lt;br /&gt;
 return (0);&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Overload the + relative to MyClass.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
class MyClass {&lt;br /&gt;
  int x, y; &lt;br /&gt;
public:&lt;br /&gt;
  MyClass() { &lt;br /&gt;
     x=0; &lt;br /&gt;
     y=0; &lt;br /&gt;
  }&lt;br /&gt;
  MyClass(int i, int j) { &lt;br /&gt;
     x=i; &lt;br /&gt;
     y=j; &lt;br /&gt;
  }&lt;br /&gt;
  void getXY(int &amp;amp;i, int &amp;amp;j) { &lt;br /&gt;
     i=x; &lt;br /&gt;
     j=y; &lt;br /&gt;
  }&lt;br /&gt;
  MyClass operator+(MyClass object2);&lt;br /&gt;
};&lt;br /&gt;
// Overload + &lt;br /&gt;
MyClass MyClass::operator+(MyClass object2)&lt;br /&gt;
{&lt;br /&gt;
  MyClass temp;&lt;br /&gt;
  temp.x = x + object2.x;&lt;br /&gt;
  temp.y = y + object2.y;&lt;br /&gt;
  return temp;&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  MyClass object1(10, 10), object2(5, 3), object3;&lt;br /&gt;
  int x, y;&lt;br /&gt;
  object3 = object1 + object2;     // add two objects - this calls operator+()&lt;br /&gt;
  object3.getXY(x, y);&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;(object1+object2) X: &amp;quot; &amp;lt;&amp;lt; x &amp;lt;&amp;lt; &amp;quot;, Y: &amp;quot; &amp;lt;&amp;lt; y &amp;lt;&amp;lt; endl;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==String class with custom +/- operator==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;   &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
class String &lt;br /&gt;
{&lt;br /&gt;
  public: &lt;br /&gt;
    char *operator +(char *append_str)&lt;br /&gt;
    { return(strcat(buffer, append_str)); };&lt;br /&gt;
   &lt;br /&gt;
    char *operator -(char letter);&lt;br /&gt;
    String(char *string) &lt;br /&gt;
    { strcpy(buffer, string); &lt;br /&gt;
        length = strlen(buffer); &lt;br /&gt;
    }&lt;br /&gt;
    void show_string() { cout &amp;lt;&amp;lt; buffer; };&lt;br /&gt;
  private:&lt;br /&gt;
    char buffer[256];&lt;br /&gt;
    int length;&lt;br /&gt;
};&lt;br /&gt;
int main(void){&lt;br /&gt;
   String title(&amp;quot;A&amp;quot;);&lt;br /&gt;
   title = title + &amp;quot;Programmer&amp;quot;s Bible\n&amp;quot;;&lt;br /&gt;
   title.show_string();&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>