<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Constructor on Cheat Sheet</title><link>/tags/constructor/</link><description>Recent content in Constructor on Cheat Sheet</description><generator>Hugo</generator><language>en</language><atom:link href="/tags/constructor/index.xml" rel="self" type="application/rss+xml"/><item><title>Classes</title><link>/programming/cpp/primer/classes/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/programming/cpp/primer/classes/</guid><description>&lt;h1 id="classes"&gt;Classes&lt;a class="anchor" href="#classes"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Based on &lt;em&gt;C++ Primer, 5th ed.&lt;/em&gt; Chapter 7 (Classes).&lt;/p&gt;
&lt;h2 id="1-member-functions-and-the-implicit-this-pointer"&gt;1. Member Functions and the Implicit &lt;code&gt;this&lt;/code&gt; Pointer&lt;a class="anchor" href="#1-member-functions-and-the-implicit-this-pointer"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Member functions access the object on which they were called through an extra, implicit parameter named &lt;code&gt;this&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;It is illegal for us to define a parameter or variable named &lt;code&gt;this&lt;/code&gt;, because &lt;code&gt;this&lt;/code&gt; is intended to always refer to &amp;ldquo;this&amp;rdquo; object, &lt;code&gt;this&lt;/code&gt; is a &lt;code&gt;const&lt;/code&gt; pointer. (&lt;code&gt;CLASS *const this&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="const-member-functions"&gt;&lt;code&gt;const&lt;/code&gt; Member Functions&lt;a class="anchor" href="#const-member-functions"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;A &lt;strong&gt;&lt;code&gt;const&lt;/code&gt; member function&lt;/strong&gt; (a member function with &lt;code&gt;const&lt;/code&gt; placed after the parameter list &lt;code&gt;()&lt;/code&gt;, e.g., &lt;code&gt;void bar() const&lt;/code&gt;) changes &lt;code&gt;this&lt;/code&gt; to &lt;code&gt;const CLASS *const this&lt;/code&gt; so that the object cannot be modified.&lt;/p&gt;</description></item></channel></rss>