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_Tutorial%2FClass%2Fthis</id>
		<title>C++ Tutorial/Class/this - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B_Tutorial%2FClass%2Fthis"/>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B_Tutorial/Class/this&amp;action=history"/>
		<updated>2026-04-10T21:54:52Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B_Tutorial/Class/this&amp;diff=2307&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_Tutorial/Class/this&amp;diff=2307&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://cppe.ru/index.php?title=C%2B%2B_Tutorial/Class/this&amp;diff=2308&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_Tutorial/Class/this&amp;diff=2308&amp;oldid=prev"/>
				<updated>2010-05-25T10:29: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;==Cascading member function calls with the this pointer==&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;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
using std::setfill;&lt;br /&gt;
using std::setw;&lt;br /&gt;
class Time &lt;br /&gt;
{&lt;br /&gt;
public:&lt;br /&gt;
   Time( int = 0, int = 0, int = 0 );&lt;br /&gt;
   Time &amp;amp;setTime( int, int, int );&lt;br /&gt;
   Time &amp;amp;setHour( int );&lt;br /&gt;
   Time &amp;amp;setMinute( int );&lt;br /&gt;
   Time &amp;amp;setSecond( int );&lt;br /&gt;
   int getHour() const;&lt;br /&gt;
   int getMinute() const;&lt;br /&gt;
   int getSecond() const;&lt;br /&gt;
   void printUniversal() const;&lt;br /&gt;
private:&lt;br /&gt;
   int hour;&lt;br /&gt;
   int minute;&lt;br /&gt;
   int second;&lt;br /&gt;
};&lt;br /&gt;
Time::Time( int hr, int min, int sec ) &lt;br /&gt;
{ &lt;br /&gt;
   setTime( hr, min, sec ); &lt;br /&gt;
}&lt;br /&gt;
Time &amp;amp;Time::setTime( int h, int m, int s )&lt;br /&gt;
{&lt;br /&gt;
   setHour( h );&lt;br /&gt;
   setMinute( m );&lt;br /&gt;
   setSecond( s ); &lt;br /&gt;
   return *this;&lt;br /&gt;
}&lt;br /&gt;
Time &amp;amp;Time::setHour( int h )&lt;br /&gt;
{&lt;br /&gt;
   hour = h;&lt;br /&gt;
   return *this; &lt;br /&gt;
}&lt;br /&gt;
Time &amp;amp;Time::setMinute( int m )&lt;br /&gt;
{&lt;br /&gt;
   minute = m;&lt;br /&gt;
   return *this;&lt;br /&gt;
}&lt;br /&gt;
Time &amp;amp;Time::setSecond( int s )&lt;br /&gt;
{&lt;br /&gt;
   second = s;&lt;br /&gt;
   return *this;&lt;br /&gt;
}&lt;br /&gt;
int Time::getHour() const &lt;br /&gt;
{ &lt;br /&gt;
   return hour; &lt;br /&gt;
}&lt;br /&gt;
int Time::getMinute() const &lt;br /&gt;
{ &lt;br /&gt;
   return minute; &lt;br /&gt;
}&lt;br /&gt;
int Time::getSecond() const &lt;br /&gt;
{ &lt;br /&gt;
   return second; &lt;br /&gt;
}&lt;br /&gt;
void Time::printUniversal() const&lt;br /&gt;
{&lt;br /&gt;
   cout &amp;lt;&amp;lt; hour &amp;lt;&amp;lt; &amp;quot;:&amp;quot; &amp;lt;&amp;lt; minute &amp;lt;&amp;lt; &amp;quot;:&amp;quot; &amp;lt;&amp;lt; second;&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   Time t;&lt;br /&gt;
   t.setHour( 18 ).setMinute( 30 ).setSecond( 22 );&lt;br /&gt;
   t.printUniversal();&lt;br /&gt;
   t.setTime( 20, 20, 20 ).printUniversal();&lt;br /&gt;
   cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
   return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;18:30:2220:20:20&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Returning the dereferenced this pointer==&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;
     const MyType&amp;amp; operator++ ();      // prefix&lt;br /&gt;
     const MyType operator++ (int);    // postfix&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;
 const MyType MyType::operator++(int)&lt;br /&gt;
 {&lt;br /&gt;
     MyType temp(*this);&lt;br /&gt;
     ++myValue;&lt;br /&gt;
     return temp;&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++;&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;
     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&lt;br /&gt;
The value of a: 3 and i: 4&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use the &amp;quot;this&amp;quot; pointer.==&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 MyClass { &lt;br /&gt;
  int i; &lt;br /&gt;
public: &lt;br /&gt;
  void setI(int val) { &lt;br /&gt;
    this-&amp;gt;i = val; &lt;br /&gt;
  }  &lt;br /&gt;
  int getI() { &lt;br /&gt;
    return this-&amp;gt;i; &lt;br /&gt;
  }  &lt;br /&gt;
} ; &lt;br /&gt;
 &lt;br /&gt;
int main() &lt;br /&gt;
{ &lt;br /&gt;
  MyClass o; &lt;br /&gt;
 &lt;br /&gt;
  o.setI(100); &lt;br /&gt;
  cout &amp;lt;&amp;lt; o.getI(); &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;100&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using the this pointer==&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 Rectangle&lt;br /&gt;
 {&lt;br /&gt;
 public:&lt;br /&gt;
     Rectangle();&lt;br /&gt;
     ~Rectangle();&lt;br /&gt;
     void SetLength(int length) { this-&amp;gt;itsLength = length; }&lt;br /&gt;
     int GetLength() const { return this-&amp;gt;itsLength; }&lt;br /&gt;
     void SetWidth(int width) { itsWidth = width; }&lt;br /&gt;
     int GetWidth() const { return itsWidth; }&lt;br /&gt;
 &lt;br /&gt;
 private:&lt;br /&gt;
     int itsLength;&lt;br /&gt;
     int itsWidth;&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 Rectangle::Rectangle()&lt;br /&gt;
 {&lt;br /&gt;
     itsWidth = 5;&lt;br /&gt;
     itsLength = 10;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 Rectangle::~Rectangle()&lt;br /&gt;
 {}&lt;br /&gt;
 &lt;br /&gt;
 int main()&lt;br /&gt;
 {&lt;br /&gt;
     Rectangle theRect;&lt;br /&gt;
     std::cout &amp;lt;&amp;lt; &amp;quot;theRect is &amp;quot; &amp;lt;&amp;lt; theRect.GetLength() &lt;br /&gt;
               &amp;lt;&amp;lt; &amp;quot; feet long.\n&amp;quot;;&lt;br /&gt;
     std::cout &amp;lt;&amp;lt; &amp;quot;theRect is &amp;quot; &amp;lt;&amp;lt; theRect.GetWidth() &lt;br /&gt;
               &amp;lt;&amp;lt; &amp;quot; feet wide.\n&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
     theRect.SetLength(20);&lt;br /&gt;
     theRect.SetWidth(10);&lt;br /&gt;
     std::cout &amp;lt;&amp;lt; &amp;quot;theRect is &amp;quot; &amp;lt;&amp;lt; theRect.GetLength()&lt;br /&gt;
               &amp;lt;&amp;lt; &amp;quot; feet long.\n&amp;quot;;&lt;br /&gt;
     std::cout &amp;lt;&amp;lt; &amp;quot;theRect is &amp;quot; &amp;lt;&amp;lt; theRect.GetWidth()&lt;br /&gt;
               &amp;lt;&amp;lt; &amp;quot; feet wide.\n&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;theRect is 10 feet long.&lt;br /&gt;
theRect is 5 feet wide.&lt;br /&gt;
theRect is 20 feet long.&lt;br /&gt;
theRect is 10 feet wide.&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>