<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
<channel>
	<title>Comments for Learn C++</title>
	
	<link>http://www.learncpp.com</link>
	<description />
	<lastBuildDate>Fri, 12 Mar 2010 16:52:45 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/LearnCppComments" /><feedburner:info uri="learncppcomments" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:browserFriendly></feedburner:browserFriendly><item>
		<title>Comment on 9.12 — Shallow vs. deep copying by Phil Braun</title>
		<link>http://www.learncpp.com/cpp-tutorial/912-shallow-vs-deep-copying/comment-page-1/#comment-80369</link>
		<dc:creator>Phil Braun</dc:creator>
		<pubDate>Fri, 12 Mar 2010 16:52:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/912-shallow-vs-deep-copying/#comment-80369</guid>
		<description>In the following example pulled from the article, there seems to be two problems that can occur.

&lt;pre&gt;
// Assignment operator
MyString&amp; MyString::operator=(const MyString&amp; cSource)
{
    // check for self-assignment
    if (this == &amp;cSource)
        return *this;

    // first we need to deallocate any value that this string is holding!
    delete[] m_pchString;

    // because m_nLength is not a pointer, we can shallow copy it
    m_nLength = cSource.m_nLength;

    // now we need to deep copy m_pchString
    if (cSource.m_pchString)
    {
        // allocate memory for our copy
        m_pchString = new char[m_nLength];

        // Copy the parameter the newly allocated memory
        strncpy(m_pchString, cSource.m_pchString, m_nLength);
    }
    else
        m_pchString = 0;

    return *this;
}&lt;/pre&gt;

The first problem is the line "delete[] m_pchString;". If "m_pchString" is not allocated, could this cause an exception? Would it not be better to check if "m_pchString" is valid before attempting to delete the memory?

The second problem occurs if "cSource.m_pchString" is a zero length string. Would it not be better to assign NULL to m_pchString if "cSource.m_pchString" has zero length? Oh, and what happens when an attempt is made to create a zero length string in the "new" statement and when "strncpy" attempts to copy a zero length string?

Otherwise this code is a good learning tool.


Phil</description>
		<content:encoded><![CDATA[<p>In the following example pulled from the article, there seems to be two problems that can occur.</p>
<pre>
// Assignment operator
MyString&amp; MyString::operator=(const MyString&amp; cSource)
{
    // check for self-assignment
    if (this == &amp;cSource)
        return *this;

    // first we need to deallocate any value that this string is holding!
    delete[] m_pchString;

    // because m_nLength is not a pointer, we can shallow copy it
    m_nLength = cSource.m_nLength;

    // now we need to deep copy m_pchString
    if (cSource.m_pchString)
    {
        // allocate memory for our copy
        m_pchString = new char[m_nLength];

        // Copy the parameter the newly allocated memory
        strncpy(m_pchString, cSource.m_pchString, m_nLength);
    }
    else
        m_pchString = 0;

    return *this;
}</pre>
<p>The first problem is the line &#8220;delete[] m_pchString;&#8221;. If &#8220;m_pchString&#8221; is not allocated, could this cause an exception? Would it not be better to check if &#8220;m_pchString&#8221; is valid before attempting to delete the memory?</p>
<p>The second problem occurs if &#8220;cSource.m_pchString&#8221; is a zero length string. Would it not be better to assign NULL to m_pchString if &#8220;cSource.m_pchString&#8221; has zero length? Oh, and what happens when an attempt is made to create a zero length string in the &#8220;new&#8221; statement and when &#8220;strncpy&#8221; attempts to copy a zero length string?</p>
<p>Otherwise this code is a good learning tool.</p>
<p>Phil</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on 1.7 — Forward declarations by Ireul</title>
		<link>http://www.learncpp.com/cpp-tutorial/17-forward-declarations/comment-page-1/#comment-80357</link>
		<dc:creator>Ireul</dc:creator>
		<pubDate>Fri, 12 Mar 2010 12:16:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=28#comment-80357</guid>
		<description>Sorry for disrespectful comment, but you miss grade school math classes.

7 + 8 - 3 * 7 = 15 - 21 = -6, the answer given by output is perfectly correct.</description>
		<content:encoded><![CDATA[<p>Sorry for disrespectful comment, but you miss grade school math classes.</p>
<p>7 + 8 &#8211; 3 * 7 = 15 &#8211; 21 = -6, the answer given by output is perfectly correct.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on 1.5 — A first look at operators by Insert Name Here</title>
		<link>http://www.learncpp.com/cpp-tutorial/15-a-first-look-at-operators/comment-page-1/#comment-80328</link>
		<dc:creator>Insert Name Here</dc:creator>
		<pubDate>Fri, 12 Mar 2010 03:15:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=40#comment-80328</guid>
		<description>Most easy to understand tutorial I have come across</description>
		<content:encoded><![CDATA[<p>Most easy to understand tutorial I have come across</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on 12.5 — The virtual table by kumar</title>
		<link>http://www.learncpp.com/cpp-tutorial/125-the-virtual-table/comment-page-2/#comment-80272</link>
		<dc:creator>kumar</dc:creator>
		<pubDate>Thu, 11 Mar 2010 11:18:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/125-the-virtual-table/#comment-80272</guid>
		<description>&lt;pre&gt;
//with out key word virtual 
class Base
{
public :
	  void go()
	 {
		 cout&lt;&lt;"\n i am in base:";
	 }
};
class D1 : public Base
{
public : 
	void go()
	{
		cout&lt;&lt;"\n I am in d1:";
	}
};

class D2 : public Base
{
public :
	        void go()
			{
		cout&lt;&lt;"\n i am in d2:";
			}
};
int main()
{
Base *ptr = new D2();
((D1*)ptr)-&gt;go();  //It will call D1

((D2*)ptr)-&gt;go();  //It will call D2

return 0;
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<pre>
//with out key word virtual
class Base
{
public :
	  void go()
	 {
		 cout&lt;&lt;&quot;\n i am in base:&quot;;
	 }
};
class D1 : public Base
{
public :
	void go()
	{
		cout&lt;&lt;&quot;\n I am in d1:&quot;;
	}
};

class D2 : public Base
{
public :
	        void go()
			{
		cout&lt;&lt;&quot;\n i am in d2:&quot;;
			}
};
int main()
{
Base *ptr = new D2();
((D1*)ptr)-&gt;go();  //It will call D1

((D2*)ptr)-&gt;go();  //It will call D2

return 0;
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on 12.5 — The virtual table by kumar</title>
		<link>http://www.learncpp.com/cpp-tutorial/125-the-virtual-table/comment-page-2/#comment-80271</link>
		<dc:creator>kumar</dc:creator>
		<pubDate>Thu, 11 Mar 2010 11:12:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/125-the-virtual-table/#comment-80271</guid>
		<description>&lt;pre&gt;

class Base
{
public :
	  void go()
	 {
		 cout&lt;&lt;"\n i am in base:";
	 }
};
class D1 : public Base
{
public : 
	void go()
	{
		cout&lt;&lt;"\n I am in d1:";
	}
};

class D2 : public Base
{
public :
	        void go()
			{
				cout&lt;&lt;"\n i am in d2:";
			}
};

int main()
{
Base *ptr = new D2();
((D1*)ptr)-&gt;go();   // it will call D1
((D2*)ptr)-&gt;go();   // it will call D2
return 0;
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<pre>

class Base
{
public :
	  void go()
	 {
		 cout&lt;&lt;&quot;\n i am in base:&quot;;
	 }
};
class D1 : public Base
{
public :
	void go()
	{
		cout&lt;&lt;&quot;\n I am in d1:&quot;;
	}
};

class D2 : public Base
{
public :
	        void go()
			{
				cout&lt;&lt;&quot;\n i am in d2:&quot;;
			}
};

int main()
{
Base *ptr = new D2();
((D1*)ptr)-&gt;go();   // it will call D1
((D2*)ptr)-&gt;go();   // it will call D2
return 0;
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on 12.5 — The virtual table by kumar</title>
		<link>http://www.learncpp.com/cpp-tutorial/125-the-virtual-table/comment-page-2/#comment-80270</link>
		<dc:creator>kumar</dc:creator>
		<pubDate>Thu, 11 Mar 2010 11:10:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/125-the-virtual-table/#comment-80270</guid>
		<description>&lt;pre&gt;
//good example with out key word virtual */
class Base
{
public :
	  void go()
	 {
		 cout&lt;&lt;"\n i am in base:";
	 }
};
class D1 : public Base
{
public : 
	void go()
	{
		cout&lt;&lt;"\n I am in d1:";
	}
};

class D2 : public Base
{
public :
	        void go()
			{
				cout&lt;go();  // it will execute D2
((D1*)ptr)-&gt;go();  // it will execute D1
 

return o;
}</description>
		<content:encoded><![CDATA[<pre>
//good example with out key word virtual */
class Base
{
public :
	  void go()
	 {
		 cout&lt;&lt;&quot;\n i am in base:&quot;;
	 }
};
class D1 : public Base
{
public :
	void go()
	{
		cout&lt;&lt;&quot;\n I am in d1:&quot;;
	}
};

class D2 : public Base
{
public :
	        void go()
			{
				cout&lt;go();  // it will execute D2
((D1*)ptr)-&gt;go();  // it will execute D1

return o;
}</pre>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on 1.6 — Whitespace and basic formatting by Hele</title>
		<link>http://www.learncpp.com/cpp-tutorial/16-whitespace-and-basic-formatting/comment-page-1/#comment-80244</link>
		<dc:creator>Hele</dc:creator>
		<pubDate>Thu, 11 Mar 2010 00:29:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=24#comment-80244</guid>
		<description>THANKS A LOT for this tutorial :) ...I'm actually having fun! ;)</description>
		<content:encoded><![CDATA[<p>THANKS A LOT for this tutorial :) &#8230;I&#8217;m actually having fun! ;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on 5.6 — Do while statements by Scott</title>
		<link>http://www.learncpp.com/cpp-tutorial/56-do-while-statements/comment-page-1/#comment-80220</link>
		<dc:creator>Scott</dc:creator>
		<pubDate>Wed, 10 Mar 2010 16:31:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/56-do-while-statements/#comment-80220</guid>
		<description>It will only print 12 since the next time through the loop; x will be 11 and 11 is not less than 7. you need to use x&gt;7. You should also use
cout &lt;&lt; x &lt;&lt; endl; or printf ("%d\n", x); You forgot the forward slash.</description>
		<content:encoded><![CDATA[<p>It will only print 12 since the next time through the loop; x will be 11 and 11 is not less than 7. you need to use x&gt;7. You should also use<br />
cout &lt;&lt; x &lt;&lt; endl; or printf (&quot;%d\n&quot;, x); You forgot the forward slash.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on 1.2 — Comments by seb</title>
		<link>http://www.learncpp.com/cpp-tutorial/12-comments/comment-page-1/#comment-80102</link>
		<dc:creator>seb</dc:creator>
		<pubDate>Tue, 09 Mar 2010 02:02:41 +0000</pubDate>
		<guid isPermaLink="false">http://learncpp.com/?p=21#comment-80102</guid>
		<description>what do u mean by commenting out a code</description>
		<content:encoded><![CDATA[<p>what do u mean by commenting out a code</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on 8.9 — Class code and header files by Thabo</title>
		<link>http://www.learncpp.com/cpp-tutorial/89-class-code-and-header-files/comment-page-1/#comment-80086</link>
		<dc:creator>Thabo</dc:creator>
		<pubDate>Mon, 08 Mar 2010 20:50:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/89-class-code-and-header-files/#comment-80086</guid>
		<description>all what you have written is right as long as the program is running the way you expect</description>
		<content:encoded><![CDATA[<p>all what you have written is right as long as the program is running the way you expect</p>
]]></content:encoded>
	</item>
</channel>
</rss><!-- Dynamic page generated in 0.136 seconds. --><!-- Cached page generated by WP-Super-Cache on 2010-03-12 14:00:17 -->
