A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B_Tutorial%2FOperator_Overloading%2Foverload_unary_operator</id>
		<title>C++ Tutorial/Operator Overloading/overload unary operator - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B_Tutorial%2FOperator_Overloading%2Foverload_unary_operator"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B_Tutorial/Operator_Overloading/overload_unary_operator&amp;action=history"/>
		<updated>2026-04-17T23:33:50Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B_Tutorial/Operator_Overloading/overload_unary_operator&amp;diff=2817&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B_Tutorial/Operator_Overloading/overload_unary_operator&amp;diff=2817&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:17Z</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://www.cppe.ru/index.php?title=C%2B%2B_Tutorial/Operator_Overloading/overload_unary_operator&amp;diff=2818&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B_Tutorial/Operator_Overloading/overload_unary_operator&amp;diff=2818&amp;oldid=prev"/>
				<updated>2010-05-25T10:30:36Z</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;==Demonstrate prefix and postfix ++==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt; &lt;br /&gt;
using namespace std; &lt;br /&gt;
 &lt;br /&gt;
class ThreeD { &lt;br /&gt;
  int x, y, z; &lt;br /&gt;
public: &lt;br /&gt;
  ThreeD() { x = y = z = 0; } &lt;br /&gt;
  ThreeD(int i, int j, int k) {x = i; y = j; z = k; } &lt;br /&gt;
 &lt;br /&gt;
  ThreeD operator++(); // prefix version of ++ &lt;br /&gt;
  ThreeD operator++(int notused); // postfix version of ++ &lt;br /&gt;
 &lt;br /&gt;
  void show() ; &lt;br /&gt;
}; &lt;br /&gt;
 &lt;br /&gt;
// Overload the prefix version of ++. &lt;br /&gt;
ThreeD ThreeD::operator++() &lt;br /&gt;
{ &lt;br /&gt;
  x++;  // increment x, y, and z &lt;br /&gt;
  y++; &lt;br /&gt;
  z++; &lt;br /&gt;
  return *this; // return altered value &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
// Overload the postfix version of ++. &lt;br /&gt;
ThreeD ThreeD::operator++(int notused) &lt;br /&gt;
{ &lt;br /&gt;
  ThreeD temp = *this; // save original value &lt;br /&gt;
 &lt;br /&gt;
  x++; // increment x, y, and z &lt;br /&gt;
  y++; &lt;br /&gt;
  z++; &lt;br /&gt;
  return temp; // return original value &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
// Show X, Y, Z coordinates. &lt;br /&gt;
void ThreeD::show( ) &lt;br /&gt;
{ &lt;br /&gt;
  cout &amp;lt;&amp;lt; x &amp;lt;&amp;lt; &amp;quot;, &amp;quot;; &lt;br /&gt;
  cout &amp;lt;&amp;lt; y &amp;lt;&amp;lt; &amp;quot;, &amp;quot;; &lt;br /&gt;
  cout &amp;lt;&amp;lt; z &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;; &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
int main() &lt;br /&gt;
{ &lt;br /&gt;
  ThreeD a(1, 2, 3); &lt;br /&gt;
  ThreeD b; &lt;br /&gt;
 &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Original value of a: &amp;quot;; &lt;br /&gt;
  a.show(); &lt;br /&gt;
 &lt;br /&gt;
  ++a; // prefix increment &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Value after ++a: &amp;quot;; &lt;br /&gt;
  a.show(); &lt;br /&gt;
 &lt;br /&gt;
  a++; // postfix increment &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Value after a++: &amp;quot;; &lt;br /&gt;
  a.show(); &lt;br /&gt;
 &lt;br /&gt;
  b = ++a; &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;\nValue of a after b = ++a: &amp;quot;; &lt;br /&gt;
  a.show(); &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Value of b after b = ++a: &amp;quot;; &lt;br /&gt;
  b.show(); &lt;br /&gt;
 &lt;br /&gt;
  b = a++; &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;\nValue of a after b = a++: &amp;quot;; &lt;br /&gt;
  a.show(); &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Value of b after b = a++: &amp;quot;; &lt;br /&gt;
  b.show(); &lt;br /&gt;
 &lt;br /&gt;
  return 0; &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Original value of a: 1, 2, 3&lt;br /&gt;
Value after ++a: 2, 3, 4&lt;br /&gt;
Value after a++: 3, 4, 5&lt;br /&gt;
Value of a after b = ++a: 4, 5, 6&lt;br /&gt;
Value of b after b = ++a: 4, 5, 6&lt;br /&gt;
Value of a after b = a++: 5, 6, 7&lt;br /&gt;
Value of b after b = a++: 4, 5, 6&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Lvalues and rvalues==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
class number {&lt;br /&gt;
public:&lt;br /&gt;
  number(int i = 0) : value(i) {&lt;br /&gt;
  }&lt;br /&gt;
  operator int() const {&lt;br /&gt;
    return value;&lt;br /&gt;
  }&lt;br /&gt;
  number&amp;amp; operator=(const number&amp;amp; n) {&lt;br /&gt;
    std::cout&amp;lt;&amp;lt;&amp;quot;=&amp;quot;;&lt;br /&gt;
    value = static_cast&amp;lt;int&amp;gt;(n);&lt;br /&gt;
    return *this;&lt;br /&gt;
  }&lt;br /&gt;
private:&lt;br /&gt;
  int value;&lt;br /&gt;
};&lt;br /&gt;
number operator+(const number&amp;amp; x, const number&amp;amp; y)&lt;br /&gt;
{&lt;br /&gt;
  std::cout&amp;lt;&amp;lt;&amp;quot;+&amp;quot;;&lt;br /&gt;
  return number(static_cast&amp;lt;int&amp;gt;(x) + static_cast&amp;lt;int&amp;gt;(y));&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  number a[10], b(42);&lt;br /&gt;
  number* p;&lt;br /&gt;
  a;           // lvalue&lt;br /&gt;
  a[0];        // lvalue&lt;br /&gt;
  &amp;amp;a[0];       // rvalue&lt;br /&gt;
  *a;          // lvalue&lt;br /&gt;
  p;           // lvalue&lt;br /&gt;
  *p;          // lvalue&lt;br /&gt;
  10;          // rvalue&lt;br /&gt;
  number(10);  // rvalue&lt;br /&gt;
  a[0] + b;    // rvalue&lt;br /&gt;
  b = a[0];    // lvalue&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;+=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Overloading ++==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
class MyType {&lt;br /&gt;
  public:&lt;br /&gt;
    MyType (int arg = 0) : x(arg) {&lt;br /&gt;
    }&lt;br /&gt;
    bool operator!=(const MyType&amp;amp; arg) const {      &lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;comparing&amp;quot; &amp;lt;&amp;lt; endl;  &lt;br /&gt;
      return x != arg.x;&lt;br /&gt;
    }&lt;br /&gt;
    int operator*() const { return x; }              &lt;br /&gt;
    MyType&amp;amp; operator++() {                          &lt;br /&gt;
      ++x;&lt;br /&gt;
      return *this;&lt;br /&gt;
    }&lt;br /&gt;
  private:&lt;br /&gt;
    int x;&lt;br /&gt;
};&lt;br /&gt;
int main() {&lt;br /&gt;
  MyType begin(3);&lt;br /&gt;
  MyType end(7);&lt;br /&gt;
  &lt;br /&gt;
  for( ; begin != end ; ++begin)&lt;br /&gt;
    cout &amp;lt;&amp;lt; *begin &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
  &lt;br /&gt;
  return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;comparing&lt;br /&gt;
3 comparing&lt;br /&gt;
4 comparing&lt;br /&gt;
5 comparing&lt;br /&gt;
6 comparing&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Overloading the increment operator==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 class MyType&lt;br /&gt;
 {&lt;br /&gt;
 public:&lt;br /&gt;
     MyType();&lt;br /&gt;
     ~MyType(){}&lt;br /&gt;
     int getValue()const { &lt;br /&gt;
        return myValue; &lt;br /&gt;
     }&lt;br /&gt;
     void setValue(int x) {&lt;br /&gt;
        myValue = x; &lt;br /&gt;
     }&lt;br /&gt;
     void Increment() { &lt;br /&gt;
        ++myValue; &lt;br /&gt;
     }&lt;br /&gt;
     const MyType&amp;amp; operator++ ();&lt;br /&gt;
 &lt;br /&gt;
 private:&lt;br /&gt;
     int myValue;&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 MyType::MyType():myValue(0){}&lt;br /&gt;
 &lt;br /&gt;
 const MyType&amp;amp; MyType::operator++()&lt;br /&gt;
 {&lt;br /&gt;
     ++myValue;&lt;br /&gt;
     return *this;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 int main()&lt;br /&gt;
 {&lt;br /&gt;
     MyType i;&lt;br /&gt;
     std::cout &amp;lt;&amp;lt; &amp;quot;The value of i is &amp;quot; &amp;lt;&amp;lt; i.getValue() &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
     i.Increment();&lt;br /&gt;
     std::cout &amp;lt;&amp;lt; &amp;quot;The value of i is &amp;quot; &amp;lt;&amp;lt; i.getValue() &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
     ++i;&lt;br /&gt;
     std::cout &amp;lt;&amp;lt; &amp;quot;The value of i is &amp;quot; &amp;lt;&amp;lt; i.getValue() &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
     MyType a = ++i;&lt;br /&gt;
     std::cout &amp;lt;&amp;lt; &amp;quot;The value of a: &amp;quot; &amp;lt;&amp;lt; a.getValue();&lt;br /&gt;
     std::cout &amp;lt;&amp;lt; &amp;quot; and i: &amp;quot; &amp;lt;&amp;lt; i.getValue() &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
     return 0;&lt;br /&gt;
 }&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;The value of i is 0&lt;br /&gt;
The value of i is 1&lt;br /&gt;
The value of i is 2&lt;br /&gt;
The value of a: 3 and i: 3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Overload prefix ++ for Point==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
class Point {&lt;br /&gt;
  int x, y;&lt;br /&gt;
public:&lt;br /&gt;
  Point() {} // needed to construct temporaries&lt;br /&gt;
  Point(int px, int py) {&lt;br /&gt;
    x = px;&lt;br /&gt;
    y = py;&lt;br /&gt;
  }&lt;br /&gt;
  void show() {&lt;br /&gt;
    cout &amp;lt;&amp;lt; x &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
    cout &amp;lt;&amp;lt; y &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
  Point operator+(Point op2);&lt;br /&gt;
  Point operator-(Point op2);&lt;br /&gt;
  Point operator=(Point op2);&lt;br /&gt;
  Point operator++();&lt;br /&gt;
};&lt;br /&gt;
// Overload + for Point.&lt;br /&gt;
Point Point::operator+(Point op2)&lt;br /&gt;
{&lt;br /&gt;
  Point temp;&lt;br /&gt;
  temp.x = op2.x + x;&lt;br /&gt;
  temp.y = op2.y + y;&lt;br /&gt;
  return temp;&lt;br /&gt;
}&lt;br /&gt;
// Overload - for Point.&lt;br /&gt;
Point Point::operator-(Point op2)&lt;br /&gt;
{&lt;br /&gt;
  Point temp;&lt;br /&gt;
  // notice order of operands&lt;br /&gt;
  temp.x = x - op2.x;&lt;br /&gt;
  temp.y = y - op2.y;&lt;br /&gt;
  return temp;&lt;br /&gt;
}&lt;br /&gt;
// Overload asignment for Point.&lt;br /&gt;
Point Point::operator=(Point op2)&lt;br /&gt;
{&lt;br /&gt;
  x = op2.x;&lt;br /&gt;
  y = op2.y;&lt;br /&gt;
  return *this; // i.e., return object that generated call&lt;br /&gt;
}&lt;br /&gt;
// Overload prefix ++ for Point.&lt;br /&gt;
Point Point::operator++()&lt;br /&gt;
{&lt;br /&gt;
  x++;&lt;br /&gt;
  y++;&lt;br /&gt;
  return *this;&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  Point ob1(10, 20), ob2( 5, 30), ob3(90, 90);&lt;br /&gt;
  ob1.show();&lt;br /&gt;
  ob2.show();&lt;br /&gt;
  ++ob1;&lt;br /&gt;
  ob1.show(); // displays 11 21&lt;br /&gt;
  ob2 = ++ob1;&lt;br /&gt;
  ob1.show(); // displays 12 22&lt;br /&gt;
  ob2.show(); // displays 12 22&lt;br /&gt;
  ob1 = ob2 = ob3; // multiple assignment&lt;br /&gt;
  ob1.show(); // displays 90 90&lt;br /&gt;
  ob2.show(); // displays 90 90&lt;br /&gt;
  return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;10 20&lt;br /&gt;
5 30&lt;br /&gt;
11 21&lt;br /&gt;
12 22&lt;br /&gt;
12 22&lt;br /&gt;
90 90&lt;br /&gt;
90 90&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Overload the postfix version of ++.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt; &lt;br /&gt;
using namespace std; &lt;br /&gt;
 &lt;br /&gt;
class ThreeD { &lt;br /&gt;
  int x, y, z; &lt;br /&gt;
public: &lt;br /&gt;
  ThreeD() { x = y = z = 0; } &lt;br /&gt;
  ThreeD(int i, int j, int k) {x = i; y = j; z = k; } &lt;br /&gt;
 &lt;br /&gt;
  ThreeD operator++(int notused); // postfix version of ++ &lt;br /&gt;
 &lt;br /&gt;
  void show() ; &lt;br /&gt;
} ; &lt;br /&gt;
 &lt;br /&gt;
// Show X, Y, Z coordinates. &lt;br /&gt;
void ThreeD::show() &lt;br /&gt;
{ &lt;br /&gt;
  cout &amp;lt;&amp;lt; x &amp;lt;&amp;lt; &amp;quot;, &amp;quot;; &lt;br /&gt;
  cout &amp;lt;&amp;lt; y &amp;lt;&amp;lt; &amp;quot;, &amp;quot;; &lt;br /&gt;
  cout &amp;lt;&amp;lt; z &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;; &lt;br /&gt;
} &lt;br /&gt;
ThreeD ThreeD::operator++(int notused) &lt;br /&gt;
{ &lt;br /&gt;
  ThreeD temp = *this; // save original value &lt;br /&gt;
 &lt;br /&gt;
  x++;  // increment x, y, and z &lt;br /&gt;
  y++; &lt;br /&gt;
  z++; &lt;br /&gt;
  return temp; // return original value &lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
int main() &lt;br /&gt;
{ &lt;br /&gt;
  ThreeD a(1, 2, 3); &lt;br /&gt;
 &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Original value of a: &amp;quot;; &lt;br /&gt;
  a.show(); &lt;br /&gt;
 &lt;br /&gt;
  a++;  // increment a &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Value after ++a: &amp;quot;; &lt;br /&gt;
  a.show(); &lt;br /&gt;
 &lt;br /&gt;
  return 0; &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Original value of a: 1, 2, 3&lt;br /&gt;
Value after ++a: 2, 3, 4&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Overload the ++ unary operator==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt; &lt;br /&gt;
using namespace std; &lt;br /&gt;
 &lt;br /&gt;
class ThreeD { &lt;br /&gt;
  int x, y, z; &lt;br /&gt;
public: &lt;br /&gt;
  ThreeD() { x = y = z = 0; } &lt;br /&gt;
  ThreeD(int i, int j, int k) {x = i; y = j; z = k; } &lt;br /&gt;
 &lt;br /&gt;
  ThreeD operator++(); // prefix version of ++ &lt;br /&gt;
 &lt;br /&gt;
  void show() ; &lt;br /&gt;
} ; &lt;br /&gt;
 &lt;br /&gt;
// Overload the prefix version of ++. &lt;br /&gt;
ThreeD ThreeD::operator++() &lt;br /&gt;
{ &lt;br /&gt;
  x++; // increment x, y, and z  &lt;br /&gt;
  y++;  &lt;br /&gt;
  z++; &lt;br /&gt;
  return *this; &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
// Show X, Y, Z coordinates. &lt;br /&gt;
void ThreeD::show() &lt;br /&gt;
{ &lt;br /&gt;
  cout &amp;lt;&amp;lt; x &amp;lt;&amp;lt; &amp;quot;, &amp;quot;; &lt;br /&gt;
  cout &amp;lt;&amp;lt; y &amp;lt;&amp;lt; &amp;quot;, &amp;quot;; &lt;br /&gt;
  cout &amp;lt;&amp;lt; z &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;; &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
int main() &lt;br /&gt;
{ &lt;br /&gt;
  ThreeD a(1, 2, 3); &lt;br /&gt;
 &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Original value of a: &amp;quot;; &lt;br /&gt;
  a.show(); &lt;br /&gt;
 &lt;br /&gt;
  ++a;  // increment a &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Value after ++a: &amp;quot;; &lt;br /&gt;
  a.show(); &lt;br /&gt;
 &lt;br /&gt;
  return 0; &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Original value of a: 1, 2, 3&lt;br /&gt;
Value after ++a: 2, 3, 4&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using a Friend to Overload ++ or � �==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
   &lt;br /&gt;
class loc {&lt;br /&gt;
  int longitude, latitude;&lt;br /&gt;
public:&lt;br /&gt;
  loc() {}&lt;br /&gt;
  loc(int lg, int lt) {&lt;br /&gt;
    longitude = lg;&lt;br /&gt;
    latitude = lt;&lt;br /&gt;
  }&lt;br /&gt;
   &lt;br /&gt;
  void show() {&lt;br /&gt;
    cout &amp;lt;&amp;lt; longitude &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
    cout &amp;lt;&amp;lt; latitude &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
   &lt;br /&gt;
  loc operator=(loc op2);&lt;br /&gt;
  friend loc operator++(loc &amp;amp;op);&lt;br /&gt;
  friend loc operator--(loc &amp;amp;op);&lt;br /&gt;
};&lt;br /&gt;
   &lt;br /&gt;
// Overload assignment for loc.&lt;br /&gt;
loc loc::operator=(loc op2)&lt;br /&gt;
{&lt;br /&gt;
  longitude = op2.longitude;&lt;br /&gt;
  latitude = op2.latitude;&lt;br /&gt;
   &lt;br /&gt;
  return *this; // i.e., return object that generated call&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
// Now a friend; use a reference parameter.&lt;br /&gt;
loc operator++(loc &amp;amp;op)&lt;br /&gt;
{&lt;br /&gt;
  op.longitude++;&lt;br /&gt;
  op.latitude++;&lt;br /&gt;
   &lt;br /&gt;
  return op;&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
// Make op-- a friend; use reference.&lt;br /&gt;
loc operator--(loc &amp;amp;op)&lt;br /&gt;
{&lt;br /&gt;
  op.longitude--;&lt;br /&gt;
  op.latitude--;&lt;br /&gt;
   &lt;br /&gt;
  return op;&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  loc ob1(10, 20), ob2;&lt;br /&gt;
   &lt;br /&gt;
  ob1.show();&lt;br /&gt;
  ++ob1;&lt;br /&gt;
  ob1.show(); &lt;br /&gt;
   &lt;br /&gt;
  ob2 =  ++ob1;&lt;br /&gt;
  ob2.show(); &lt;br /&gt;
   &lt;br /&gt;
  --ob2;&lt;br /&gt;
  ob2.show(); &lt;br /&gt;
   &lt;br /&gt;
  return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>