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%2FOverload%2FUnary_Operator</id>
		<title>C++/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%2FOverload%2FUnary_Operator"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Overload/Unary_Operator&amp;action=history"/>
		<updated>2026-04-18T18:03:33Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Overload/Unary_Operator&amp;diff=2019&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/Overload/Unary_Operator&amp;diff=2019&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://www.cppe.ru/index.php?title=C%2B%2B/Overload/Unary_Operator&amp;diff=2020&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/Overload/Unary_Operator&amp;diff=2020&amp;oldid=prev"/>
				<updated>2010-05-25T10:28:25Z</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;==Overload a unary operator.==&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, z; &lt;br /&gt;
public:&lt;br /&gt;
  MyClass() { &lt;br /&gt;
     x = y = z = 0; &lt;br /&gt;
  }&lt;br /&gt;
  MyClass(int i, int j, int k) {&lt;br /&gt;
     x = i; &lt;br /&gt;
     y = j; &lt;br /&gt;
     z = k; &lt;br /&gt;
  }&lt;br /&gt;
  MyClass operator+(MyClass op2); &lt;br /&gt;
  MyClass operator=(MyClass op2); &lt;br /&gt;
  MyClass operator++();           &lt;br /&gt;
  void show() ;&lt;br /&gt;
} ;&lt;br /&gt;
MyClass MyClass::operator+(MyClass op2)&lt;br /&gt;
{&lt;br /&gt;
  MyClass temp;&lt;br /&gt;
  temp.x = x + op2.x; &lt;br /&gt;
  temp.y = y + op2.y; &lt;br /&gt;
  temp.z = z + op2.z; &lt;br /&gt;
  return temp;&lt;br /&gt;
}&lt;br /&gt;
MyClass MyClass::operator=(MyClass op2)&lt;br /&gt;
{&lt;br /&gt;
  x = op2.x; // These are integer assignments&lt;br /&gt;
  y = op2.y; // and the = retains its original&lt;br /&gt;
  z = op2.z; // meaning relative to them.&lt;br /&gt;
  return *this;&lt;br /&gt;
}&lt;br /&gt;
MyClass MyClass::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;
void MyClass::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; endl;&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  MyClass a(1, 2, 3), b(10, 10, 10), c;&lt;br /&gt;
  a.show();&lt;br /&gt;
  b.show();&lt;br /&gt;
  c = a + b;     &lt;br /&gt;
  c.show();&lt;br /&gt;
  c = a + b + c; &lt;br /&gt;
  c.show();&lt;br /&gt;
  c = b = a;     &lt;br /&gt;
  c.show();&lt;br /&gt;
  b.show();&lt;br /&gt;
  ++c;           &lt;br /&gt;
  c.show();&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;
==Use a member function to overload the unary -.==&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;
  three_d operator+(three_d rh_op);&lt;br /&gt;
  three_d operator+(int rh_op);&lt;br /&gt;
  three_d operator-(three_d rh_op);&lt;br /&gt;
  three_d operator=(three_d rh_op);&lt;br /&gt;
  bool operator==(three_d rh_op);&lt;br /&gt;
  three_d operator-();&lt;br /&gt;
  friend ostream &amp;amp;operator&amp;lt;&amp;lt;(ostream &amp;amp;strm, three_d op);&lt;br /&gt;
  friend three_d operator+(int lh_op, three_d rh_op);&lt;br /&gt;
};&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;
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;
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;
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;
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;
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;
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;
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;
  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;
  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;
  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;
  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;
  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;
  if(objA == objB) &lt;br /&gt;
     cout &amp;lt;&amp;lt; &amp;quot;objA is equal to objB.\n&amp;quot;;&lt;br /&gt;
  else &lt;br /&gt;
     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;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>