<?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.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>
	<lastBuildDate>Thu, 02 Feb 2012 21:20:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: ccc</title>
		<link>http://www.learncpp.com/cpp-tutorial/85-constructors/comment-page-1/#comment-96056</link>
		<dc:creator>ccc</dc:creator>
		<pubDate>Wed, 21 Sep 2011 19:00:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-96056</guid>
		<description>Hi Alex,

  Thank you so much for such a great tutorial. However, I would like to use this section to indicate what is consistently missing in this tutorial. When discussing class, I think many reader will be more interested in object in the heap than stack. 

***
In the above example, because we declared a Date object, but there is no default constructor, m_nMonth, m_nDay, and m_nYear were never initialized. Consequently, they will hold garbage values. Generally speaking, this is why providing a default constructor is almost always a good idea:
***

will be true for stack object but it will not be true for heap object. For example:

#include 

using namespace std;

class Date
{
private:
    int m_nMonth;
    int m_nDay;
    int m_nYear;
public:
	int getMonth(){return m_nMonth;}
	int getDay(){return m_nDay;}
	int getYear(){return m_nYear;}
};

int main()
{
    Date cDate;
    // cDate&#039;s member variables now contain garbage
    // Who knows what date we&#039;ll get?

	cout &lt;&lt; cDate.getMonth() &lt;&lt; &quot;/&quot; &lt;&lt; cDate.getDay() &lt;&lt; &quot;/&quot; &lt;&lt; cDate.getYear() &lt;&lt; endl;
	Date *pDate = new Date();
	cout &lt;getMonth() &lt;&lt; &quot;/&quot; &lt;getDay() &lt;&lt; &quot;/&quot; &lt;getYear() &lt;&lt; endl;

    return 0;
}

Output:
-858993460/-858993460/-858993460
0/0/0

I found this tutorial purposely omit this distinction. Is there reason for it. However, no matter what. It is really really the greatest c++ tutorial ever. Thank you so much Alex for your hard work.</description>
		<content:encoded><![CDATA[<p>Hi Alex,</p>
<p>  Thank you so much for such a great tutorial. However, I would like to use this section to indicate what is consistently missing in this tutorial. When discussing class, I think many reader will be more interested in object in the heap than stack. </p>
<p>***<br />
In the above example, because we declared a Date object, but there is no default constructor, m_nMonth, m_nDay, and m_nYear were never initialized. Consequently, they will hold garbage values. Generally speaking, this is why providing a default constructor is almost always a good idea:<br />
***</p>
<p>will be true for stack object but it will not be true for heap object. For example:</p>
<p>#include </p>
<p>using namespace std;</p>
<p>class Date<br />
{<br />
private:<br />
    int m_nMonth;<br />
    int m_nDay;<br />
    int m_nYear;<br />
public:<br />
	int getMonth(){return m_nMonth;}<br />
	int getDay(){return m_nDay;}<br />
	int getYear(){return m_nYear;}<br />
};</p>
<p>int main()<br />
{<br />
    Date cDate;<br />
    // cDate&#8217;s member variables now contain garbage<br />
    // Who knows what date we&#8217;ll get?</p>
<p>	cout &lt;&lt; cDate.getMonth() &lt;&lt; &quot;/&quot; &lt;&lt; cDate.getDay() &lt;&lt; &quot;/&quot; &lt;&lt; cDate.getYear() &lt;&lt; endl;<br />
	Date *pDate = new Date();<br />
	cout &lt;getMonth() &lt;&lt; &quot;/&quot; &lt;getDay() &lt;&lt; &quot;/&quot; &lt;getYear() &lt;&lt; endl;</p>
<p>    return 0;<br />
}</p>
<p>Output:<br />
-858993460/-858993460/-858993460<br />
0/0/0</p>
<p>I found this tutorial purposely omit this distinction. Is there reason for it. However, no matter what. It is really really the greatest c++ tutorial ever. Thank you so much Alex for your hard work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gantashalavenki</title>
		<link>http://www.learncpp.com/cpp-tutorial/85-constructors/comment-page-1/#comment-95574</link>
		<dc:creator>gantashalavenki</dc:creator>
		<pubDate>Fri, 17 Jun 2011 07:37:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-95574</guid>
		<description>can we call constructor manually like any other member functions?....after intializing varialbes using constructor can we call constructor once again to reinitialize?</description>
		<content:encoded><![CDATA[<p>can we call constructor manually like any other member functions?&#8230;.after intializing varialbes using constructor can we call constructor once again to reinitialize?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SWEngineer</title>
		<link>http://www.learncpp.com/cpp-tutorial/85-constructors/comment-page-1/#comment-95125</link>
		<dc:creator>SWEngineer</dc:creator>
		<pubDate>Sun, 23 Jan 2011 13:04:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-95125</guid>
		<description>Simple well explained tutorial.

Thanks.</description>
		<content:encoded><![CDATA[<p>Simple well explained tutorial.</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: andi</title>
		<link>http://www.learncpp.com/cpp-tutorial/85-constructors/comment-page-1/#comment-93503</link>
		<dc:creator>andi</dc:creator>
		<pubDate>Sat, 09 Oct 2010 16:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-93503</guid>
		<description>Hi Alex, 
Just want to say ... it&#039;s really great tutorial. Thanx it helps me a lot. i like the way you make your explaination, it&#039;s simple and easy to understand.
cheers,
andi</description>
		<content:encoded><![CDATA[<p>Hi Alex,<br />
Just want to say &#8230; it&#8217;s really great tutorial. Thanx it helps me a lot. i like the way you make your explaination, it&#8217;s simple and easy to understand.<br />
cheers,<br />
andi</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vineet</title>
		<link>http://www.learncpp.com/cpp-tutorial/85-constructors/comment-page-1/#comment-93463</link>
		<dc:creator>Vineet</dc:creator>
		<pubDate>Thu, 07 Oct 2010 05:42:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-93463</guid>
		<description>hi, 
   Your tutorial is nice and gives a clear understanding of constructors. 

Thanks,
Vineet</description>
		<content:encoded><![CDATA[<p>hi,<br />
   Your tutorial is nice and gives a clear understanding of constructors. </p>
<p>Thanks,<br />
Vineet</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://www.learncpp.com/cpp-tutorial/85-constructors/comment-page-1/#comment-91331</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Fri, 03 Sep 2010 16:56:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-91331</guid>
		<description>I didn&#039;t see any comments about #include  before it is used.

I assume that it is necessary for constructors?

Tom</description>
		<content:encoded><![CDATA[<p>I didn&#8217;t see any comments about #include  before it is used.</p>
<p>I assume that it is necessary for constructors?</p>
<p>Tom</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: avolc</title>
		<link>http://www.learncpp.com/cpp-tutorial/85-constructors/comment-page-1/#comment-90532</link>
		<dc:creator>avolc</dc:creator>
		<pubDate>Thu, 19 Aug 2010 04:39:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-90532</guid>
		<description>&lt;pre&gt;string my_str(&quot;Hello World!&quot;);&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<pre>string my_str(&quot;Hello World!&quot;);</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark</title>
		<link>http://www.learncpp.com/cpp-tutorial/85-constructors/comment-page-1/#comment-78577</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Fri, 19 Feb 2010 00:01:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-78577</guid>
		<description>I haven&#039;t programmed for many years as OOP seemed too scary but it&#039;s all coming together really clearly now thanks to this this site. I&#039;m starting to see the elegance of this language. Many thanks Alex for your clear and concise tutorial.</description>
		<content:encoded><![CDATA[<p>I haven&#8217;t programmed for many years as OOP seemed too scary but it&#8217;s all coming together really clearly now thanks to this this site. I&#8217;m starting to see the elegance of this language. Many thanks Alex for your clear and concise tutorial.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aakash</title>
		<link>http://www.learncpp.com/cpp-tutorial/85-constructors/comment-page-1/#comment-74717</link>
		<dc:creator>Aakash</dc:creator>
		<pubDate>Wed, 23 Dec 2009 08:57:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-74717</guid>
		<description>Using a constructor, how would you initialize a string type with a string value?</description>
		<content:encoded><![CDATA[<p>Using a constructor, how would you initialize a string type with a string value?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://www.learncpp.com/cpp-tutorial/85-constructors/comment-page-1/#comment-72662</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Fri, 20 Nov 2009 23:24:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/85-constructors/#comment-72662</guid>
		<description>Ha.  I figured it out.  My problem was not from misusing the constructor, but that I had a loop in a cleanup function that was setting everything to 0.  This was meant to clean up other arrays that DO need to be reset each time the cleanup function was called, but for some reason I put my array of constants in the cleanup, and it was doing exactly what I told it to do.

Anyone who says computers do exactly what you tell them to do...
+1 to that. :)</description>
		<content:encoded><![CDATA[<p>Ha.  I figured it out.  My problem was not from misusing the constructor, but that I had a loop in a cleanup function that was setting everything to 0.  This was meant to clean up other arrays that DO need to be reset each time the cleanup function was called, but for some reason I put my array of constants in the cleanup, and it was doing exactly what I told it to do.</p>
<p>Anyone who says computers do exactly what you tell them to do&#8230;<br />
+1 to that. :)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

