<?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"
	>
<channel>
	<title>Comments on: 8.5 &#8212; Constructors</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/85-constructors/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/85-constructors/</link>
	<description></description>
	<pubDate>Wed, 20 Aug 2008 08:42:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Learn C++ - &#187; 8.6 &#8212; Destructors</title>
		<link>http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-23163</link>
		<dc:creator>Learn C++ - &#187; 8.6 &#8212; Destructors</dc:creator>
		<pubDate>Fri, 08 Aug 2008 17:48:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-23163</guid>
		<description>[...] 2007      Prev/Next Posts   &#171; 8.5 &#8212; Constructors &#124; Home &#124; 8.7 &#8212; The hidden &#8220;this&#8221; pointer &#187;     Thursday, September 6th, [...]</description>
		<content:encoded><![CDATA[<p>[...] 2007      Prev/Next Posts   &laquo; 8.5 &#8212; Constructors | Home | 8.7 &#8212; The hidden &#8220;this&#8221; pointer &raquo;     Thursday, September 6th, [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Learn C++ - &#187; 8.4 &#8212; Access functions and encapsulation</title>
		<link>http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-14391</link>
		<dc:creator>Learn C++ - &#187; 8.4 &#8212; Access functions and encapsulation</dc:creator>
		<pubDate>Mon, 05 May 2008 01:55:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-14391</guid>
		<description>[...] 2007      Prev/Next Posts   &#171; 8.3 &#8212; Public vs private access specifiers &#124; Home &#124; 8.5 &#8212; Constructors &#187;     Tuesday, September 4th, 2007 at 2:21 [...]</description>
		<content:encoded><![CDATA[<p>[...] 2007      Prev/Next Posts   &laquo; 8.3 &#8212; Public vs private access specifiers | Home | 8.5 &#8212; Constructors &raquo;     Tuesday, September 4th, 2007 at 2:21 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-10480</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Fri, 28 Mar 2008 04:37:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-10480</guid>
		<description>Typo:

"Date cToday(9, 5, 2007); // cDate is initialized to Sept 5th, 2007 "

Should be:

"Date cToday(9, 5, 2007); // &lt;b&gt;cToday&lt;/b&gt; is initialized to Sept 5th, 2007 "

[ Fixed.  Thanks!  -Alex ]</description>
		<content:encoded><![CDATA[<p>Typo:</p>
<p>&#8220;Date cToday(9, 5, 2007); // cDate is initialized to Sept 5th, 2007 &#8221;</p>
<p>Should be:</p>
<p>&#8220;Date cToday(9, 5, 2007); // <b>cToday</b> is initialized to Sept 5th, 2007 &#8221;</p>
<p>[ Fixed.  Thanks!  -Alex ]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-6036</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Tue, 15 Jan 2008 00:52:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-6036</guid>
		<description>In a class, you can't initialize values on the line they are declared like that.  Non-static class values should be initialized in the constructor body or initialization list.  Static class values should be initialized in the body of the class definition.

I am not sure what the reasoning is for this design decision.  I presume simply because the constructor is the function that is supposed to initialize your values.  If you were allowed to do default values this way, then many variables would be initialized twice (once in the declaration, once in the constructor).  This would be both inefficient and confusing.</description>
		<content:encoded><![CDATA[<p>In a class, you can&#8217;t initialize values on the line they are declared like that.  Non-static class values should be initialized in the constructor body or initialization list.  Static class values should be initialized in the body of the class definition.</p>
<p>I am not sure what the reasoning is for this design decision.  I presume simply because the constructor is the function that is supposed to initialize your values.  If you were allowed to do default values this way, then many variables would be initialized twice (once in the declaration, once in the constructor).  This would be both inefficient and confusing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Renu</title>
		<link>http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-6033</link>
		<dc:creator>Renu</dc:creator>
		<pubDate>Tue, 15 Jan 2008 00:22:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-6033</guid>
		<description>class Fraction   
{   
private:   
    int m_nNumerator =10;   
    int m_nDenominator=20;   
  
public:   
    Fraction() // default constructor   .......


I tried initialising m_nNumerator =10 and  int m_nDenominator=20 

got this error " only static const can be initialised ...."

Then I tried 

private:   
    static const int m_nValue=22;
    int m_nNumerator ;   
    int m_nDenominator;   
It worked.

Could you please explain? Does that mean private member variable cannot be initialised when they are declared? If so ,is there any specific reason for that?

Thanks,
Renu</description>
		<content:encoded><![CDATA[<p>class Fraction<br />
{<br />
private:<br />
    int m_nNumerator =10;<br />
    int m_nDenominator=20;   </p>
<p>public:<br />
    Fraction() // default constructor   &#8230;&#8230;.</p>
<p>I tried initialising m_nNumerator =10 and  int m_nDenominator=20 </p>
<p>got this error &#8221; only static const can be initialised &#8230;.&#8221;</p>
<p>Then I tried </p>
<p>private:<br />
    static const int m_nValue=22;<br />
    int m_nNumerator ;<br />
    int m_nDenominator;<br />
It worked.</p>
<p>Could you please explain? Does that mean private member variable cannot be initialised when they are declared? If so ,is there any specific reason for that?</p>
<p>Thanks,<br />
Renu</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Renu</title>
		<link>http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-6032</link>
		<dc:creator>Renu</dc:creator>
		<pubDate>Tue, 15 Jan 2008 00:17:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-6032</guid>
		<description>double GetFraction() { return static_cast(m_nNumerator)/nDenominator; }  


"m_nNumerator)/nDenominator"  should be "m_nNumerator)/m_nDenominator "
at all three places in the tutorial.

Thanks,
Renu</description>
		<content:encoded><![CDATA[<p>double GetFraction() { return static_cast(m_nNumerator)/nDenominator; }  </p>
<p>&#8220;m_nNumerator)/nDenominator&#8221;  should be &#8220;m_nNumerator)/m_nDenominator &#8221;<br />
at all three places in the tutorial.</p>
<p>Thanks,<br />
Renu</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-5927</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Sat, 12 Jan 2008 19:09:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-5927</guid>
		<description>I talk about assert in &lt;a href="http://www.learncpp.com/cpp-tutorial/712-handling-errors-assert-cerr-exit-and-exceptions/" rel="nofollow"&gt;section 7.12&lt;/a&gt;.  In short, it's a way to test whether an expression is true, and if not, stop the program at that point.</description>
		<content:encoded><![CDATA[<p>I talk about assert in <a href="http://www.learncpp.com/cpp-tutorial/712-handling-errors-assert-cerr-exit-and-exceptions/" rel="nofollow">section 7.12</a>.  In short, it&#8217;s a way to test whether an expression is true, and if not, stop the program at that point.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abhishek</title>
		<link>http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-5906</link>
		<dc:creator>Abhishek</dc:creator>
		<pubDate>Sat, 12 Jan 2008 08:16:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-5906</guid>
		<description>what's assert()      ?</description>
		<content:encoded><![CDATA[<p>what&#8217;s assert()      ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-5173</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Sat, 29 Dec 2007 01:32:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-5173</guid>
		<description>Great point!  I updated the example.  Dividing by 0 will definitely crash the program.</description>
		<content:encoded><![CDATA[<p>Great point!  I updated the example.  Dividing by 0 will definitely crash the program.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cody</title>
		<link>http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-5171</link>
		<dc:creator>Cody</dc:creator>
		<pubDate>Sat, 29 Dec 2007 00:42:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-5171</guid>
		<description>As a review you could include protecting m_nDenominator from invalid assumptions by making sure it is not set to 0. This is because, if I remember correctly, dividing anything by zero will probably cause the program to crash so the function GetFraction() would most likely crash the program if the denominator is 0.</description>
		<content:encoded><![CDATA[<p>As a review you could include protecting m_nDenominator from invalid assumptions by making sure it is not set to 0. This is because, if I remember correctly, dividing anything by zero will probably cause the program to crash so the function GetFraction() would most likely crash the program if the denominator is 0.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
