<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 8.10 &#8212; Const class objects and member functions</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/</link>
	<description></description>
	<lastBuildDate>Tue, 07 Feb 2012 12:30:29 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: hai</title>
		<link>http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/comment-page-1/#comment-95097</link>
		<dc:creator>hai</dc:creator>
		<pubDate>Tue, 11 Jan 2011 21:48:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/#comment-95097</guid>
		<description>const and volatile specifier for the function definition is used for the function overload.</description>
		<content:encoded><![CDATA[<p>const and volatile specifier for the function definition is used for the function overload.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sachin</title>
		<link>http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/comment-page-1/#comment-95005</link>
		<dc:creator>Sachin</dc:creator>
		<pubDate>Mon, 06 Dec 2010 10:42:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/#comment-95005</guid>
		<description>Alex,

It would be great if you could answer Anand&#039;s query since I also had the same doubt when I read the tutorial.
&quot;Overloading the function doesn’t depend on Return type of function,
Overloading the function only depend on Signature of fucntion(i.e. no of args or types of args.)

Here Overloading function GetValue 

const int&amp; GetValue() const  and 
int&amp; GetValue()

In this case, how does the compiler do name mangling?</description>
		<content:encoded><![CDATA[<p>Alex,</p>
<p>It would be great if you could answer Anand&#8217;s query since I also had the same doubt when I read the tutorial.<br />
&#8220;Overloading the function doesn’t depend on Return type of function,<br />
Overloading the function only depend on Signature of fucntion(i.e. no of args or types of args.)</p>
<p>Here Overloading function GetValue </p>
<p>const int&amp; GetValue() const  and<br />
int&amp; GetValue()</p>
<p>In this case, how does the compiler do name mangling?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob</title>
		<link>http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/comment-page-1/#comment-92054</link>
		<dc:creator>Bob</dc:creator>
		<pubDate>Tue, 14 Sep 2010 22:52:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/#comment-92054</guid>
		<description>He probs just forgot to include the const word:
&quot;This is particularly important when passing variables by const reference&quot;.</description>
		<content:encoded><![CDATA[<p>He probs just forgot to include the const word:<br />
&#8220;This is particularly important when passing variables by const reference&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vikas</title>
		<link>http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/comment-page-1/#comment-81170</link>
		<dc:creator>Vikas</dc:creator>
		<pubDate>Mon, 22 Mar 2010 08:50:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/#comment-81170</guid>
		<description>Ahh... I almost gave in for the  last part of this section.... Though confusing at the same time very simple explanation... may be for the first timers its little terrifying.. 

Hope i will come back to this section again :(</description>
		<content:encoded><![CDATA[<p>Ahh&#8230; I almost gave in for the  last part of this section&#8230;. Though confusing at the same time very simple explanation&#8230; may be for the first timers its little terrifying.. </p>
<p>Hope i will come back to this section again :(</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jay</title>
		<link>http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/comment-page-1/#comment-74932</link>
		<dc:creator>Jay</dc:creator>
		<pubDate>Sun, 27 Dec 2009 02:56:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/#comment-74932</guid>
		<description>Alex,
I doubt the below statement made in the beginning of this page is incorrect.
&quot;This is particularly important when passing variables by reference, as callers generally will not expect the values they pass to a function to be changed.&quot;

So as per this statement you are saying it is not possible to change the value in the function using the reference but of course I am very sure we can change the value. Reference is nothing but a constant pointer which means it CAN&#039;T point to another memory space once it is initialized. Of course I learned all this from your article only:p. So if you agree with me please edit the statement otherwise please correct me. Thanks.</description>
		<content:encoded><![CDATA[<p>Alex,<br />
I doubt the below statement made in the beginning of this page is incorrect.<br />
&#8220;This is particularly important when passing variables by reference, as callers generally will not expect the values they pass to a function to be changed.&#8221;</p>
<p>So as per this statement you are saying it is not possible to change the value in the function using the reference but of course I am very sure we can change the value. Reference is nothing but a constant pointer which means it CAN&#8217;T point to another memory space once it is initialized. Of course I learned all this from your article only:p. So if you agree with me please edit the statement otherwise please correct me. Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: C</title>
		<link>http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/comment-page-1/#comment-70140</link>
		<dc:creator>C</dc:creator>
		<pubDate>Sun, 11 Oct 2009 16:41:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/#comment-70140</guid>
		<description>Thanks, Alex.  It may be good to mention sneaky tricks you can do to get around const-ness.  Example:

&lt;pre&gt;
class Something
{
        public:
                int m;
                int *buffer;

                Something() {m = 0; buffer = 0;}

                void Reset() {m = 0;}
                void Set(int n) {m = n;}
                void Cheat(int index, int value) const
                {
                        buffer[index] = value;
                }

                int Get() {return m;}
};

int main()
{
        const Something thing;
        thing.Cheat(2,3);

        return 0;
}
&lt;/pre&gt;

I got this from Stephen Dewhurst&#039;s &quot;C++ Common Knowledge&quot;.  This code will compile, since Cheat() is modifying what buffer refers to, not buffer itself, even though Cheat() is declared const!</description>
		<content:encoded><![CDATA[<p>Thanks, Alex.  It may be good to mention sneaky tricks you can do to get around const-ness.  Example:</p>
<pre>
class Something
{
        public:
                int m;
                int *buffer;

                Something() {m = 0; buffer = 0;}

                void Reset() {m = 0;}
                void Set(int n) {m = n;}
                void Cheat(int index, int value) const
                {
                        buffer[index] = value;
                }

                int Get() {return m;}
};

int main()
{
        const Something thing;
        thing.Cheat(2,3);

        return 0;
}
</pre>
<p>I got this from Stephen Dewhurst&#8217;s &#8220;C++ Common Knowledge&#8221;.  This code will compile, since Cheat() is modifying what buffer refers to, not buffer itself, even though Cheat() is declared const!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: C</title>
		<link>http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/comment-page-1/#comment-70137</link>
		<dc:creator>C</dc:creator>
		<pubDate>Sun, 11 Oct 2009 16:34:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/#comment-70137</guid>
		<description>Scary.  I compiled this code using g++ and all the errors were caught.  

&lt;pre&gt;
class Something
{
public:
    int m_nValue;

    Something() { m_nValue = 0; }

    void ResetValue() { m_nValue = 0; }
    void SetValue(int nValue) { m_nValue = nValue; }

    int GetValue() { return m_nValue; }
};

int main()
{
    const Something cSomething; // calls default constructor

    cSomething.m_nValue = 5; // violates const - Compile Error
    cSomething.ResetValue(); // violates const - No error, its working
    cSomething.SetValue(5); // violates const - No error, its working

    return 0;
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Scary.  I compiled this code using g++ and all the errors were caught.  </p>
<pre>
class Something
{
public:
    int m_nValue;

    Something() { m_nValue = 0; }

    void ResetValue() { m_nValue = 0; }
    void SetValue(int nValue) { m_nValue = nValue; }

    int GetValue() { return m_nValue; }
};

int main()
{
    const Something cSomething; // calls default constructor

    cSomething.m_nValue = 5; // violates const - Compile Error
    cSomething.ResetValue(); // violates const - No error, its working
    cSomething.SetValue(5); // violates const - No error, its working

    return 0;
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anand Kumar</title>
		<link>http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/comment-page-1/#comment-65605</link>
		<dc:creator>Anand Kumar</dc:creator>
		<pubDate>Tue, 04 Aug 2009 13:23:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/#comment-65605</guid>
		<description>Hello Alex,

I am quite new to C++, Whatever I have read that Overloading the function doesn&#039;t depend on Return type of function, 
Overloading the function only depend on Signature of fucntion(i.e. no of args or types of args.)

Here one thig is confusing to me, Overloading function GetValue &lt;pre&gt; const int&amp; GetValue() const  &lt;/pre&gt; and &lt;pre&gt; int&amp; GetValue() &lt;/pre&gt;

Please help me over here.

Thanks a lot.
Anand.</description>
		<content:encoded><![CDATA[<p>Hello Alex,</p>
<p>I am quite new to C++, Whatever I have read that Overloading the function doesn&#8217;t depend on Return type of function,<br />
Overloading the function only depend on Signature of fucntion(i.e. no of args or types of args.)</p>
<p>Here one thig is confusing to me, Overloading function GetValue
<pre> const int&amp; GetValue() const  </pre>
<p> and
<pre> int&amp; GetValue() </pre>
<p>Please help me over here.</p>
<p>Thanks a lot.<br />
Anand.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fraz</title>
		<link>http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/comment-page-1/#comment-65515</link>
		<dc:creator>Fraz</dc:creator>
		<pubDate>Mon, 03 Aug 2009 03:45:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/#comment-65515</guid>
		<description>&lt;pre&gt;
class Something
{
public:
    int m_nValue;

    Something() { m_nValue = 0; }

    void ResetValue() { m_nValue = 0; }
    void SetValue(int nValue) { m_nValue = nValue; }

    int GetValue() { return m_nValue; }
};

int main()
{
    const Something cSomething; // calls default constructor

    cSomething.m_nValue = 5; // violates const - Compile Error
    cSomething.ResetValue(); // violates const - No error, its working
    cSomething.SetValue(5); // violates const - No error, its working

    return 0;
}

&lt;/pre&gt;

Im using Borland C++ 5.0 compiler and it allows non constant member functions to call constant datamembers. would u explain why above two violated rules are not caught by my compiler?</description>
		<content:encoded><![CDATA[<pre>
class Something
{
public:
    int m_nValue;

    Something() { m_nValue = 0; }

    void ResetValue() { m_nValue = 0; }
    void SetValue(int nValue) { m_nValue = nValue; }

    int GetValue() { return m_nValue; }
};

int main()
{
    const Something cSomething; // calls default constructor

    cSomething.m_nValue = 5; // violates const - Compile Error
    cSomething.ResetValue(); // violates const - No error, its working
    cSomething.SetValue(5); // violates const - No error, its working

    return 0;
}
</pre>
<p>Im using Borland C++ 5.0 compiler and it allows non constant member functions to call constant datamembers. would u explain why above two violated rules are not caught by my compiler?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fernando</title>
		<link>http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/comment-page-1/#comment-62193</link>
		<dc:creator>fernando</dc:creator>
		<pubDate>Wed, 10 Jun 2009 02:06:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/810-const-class-objects-and-member-functions/#comment-62193</guid>
		<description>Could explain the concept of explicit and implicit initialization in detail ? Does explicit mean initializing via &#039;=&#039; operator or &#039;=new type(&quot; &quot;)&#039; ?</description>
		<content:encoded><![CDATA[<p>Could explain the concept of explicit and implicit initialization in detail ? Does explicit mean initializing via &#8216;=&#8217; operator or &#8216;=new type(&#8221; &#8220;)&#8217; ?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

