<?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: 12.2 &#8212; Virtual functions</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/122-virtual-functions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/122-virtual-functions/</link>
	<description></description>
	<pubDate>Wed, 20 Aug 2008 09:18:49 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-23589</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Wed, 13 Aug 2008 17:21:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-23589</guid>
		<description>Good point.  I will make the lack of necessity and why I do this anyway clear in the text.  Thanks for your comments.</description>
		<content:encoded><![CDATA[<p>Good point.  I will make the lack of necessity and why I do this anyway clear in the text.  Thanks for your comments.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: serge</title>
		<link>http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-23459</link>
		<dc:creator>serge</dc:creator>
		<pubDate>Tue, 12 Aug 2008 16:04:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-23459</guid>
		<description>Hi,

I think this line should be :

Base &#38;rBase = cDerived;</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I think this line should be :</p>
<p>Base &amp;rBase = cDerived;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-23057</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Thu, 07 Aug 2008 14:09:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-23057</guid>
		<description>Hi Alex,
in your all your classes, whether they are derived, or base classes, you put the virtual keyword in front of the function definition of every function which shall be overwritten in the derived class, even though this is not necessary in the derived class - as long there is no class, which inherits from that, which shall overwrite the function again. It would be clearing, to point out, that it is not necessary.
Ben</description>
		<content:encoded><![CDATA[<p>Hi Alex,<br />
in your all your classes, whether they are derived, or base classes, you put the virtual keyword in front of the function definition of every function which shall be overwritten in the derived class, even though this is not necessary in the derived class - as long there is no class, which inherits from that, which shall overwrite the function again. It would be clearing, to point out, that it is not necessary.<br />
Ben</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Learn C++ - &#187; 12.3 &#8212; Virtual destructors, virtual assignment, and overriding virtualization</title>
		<link>http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-21661</link>
		<dc:creator>Learn C++ - &#187; 12.3 &#8212; Virtual destructors, virtual assignment, and overriding virtualization</dc:creator>
		<pubDate>Thu, 24 Jul 2008 01:20:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-21661</guid>
		<description>[...] 2007      Prev/Next Posts   &#171; 12.2 &#8212; Virtual functions &#124; Home &#124; 12.4 &#8212; Early binding and late binding &#187;     Friday, February 1st, 2008 at 1:50 [...]</description>
		<content:encoded><![CDATA[<p>[...] 2007      Prev/Next Posts   &laquo; 12.2 &#8212; Virtual functions | Home | 12.4 &#8212; Early binding and late binding &raquo;     Friday, February 1st, 2008 at 1:50 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-18808</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Fri, 13 Jun 2008 19:15:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-18808</guid>
		<description>You are correct.  I added a section about covariant return types.

I have also fixed the issue with the pre tags.</description>
		<content:encoded><![CDATA[<p>You are correct.  I added a section about covariant return types.</p>
<p>I have also fixed the issue with the pre tags.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve Checkoway</title>
		<link>http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-18764</link>
		<dc:creator>Steve Checkoway</dc:creator>
		<pubDate>Thu, 12 Jun 2008 21:19:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-18764</guid>
		<description>Your claim that if the derived class's function's return type differs from the function it is overriding, then the virtual function will not resolve as intended. This is incorrect. A function's return type is not part of its signature. Doing something like the following is actually quite helpful:

#include 
struct Base
{
	virtual ~Base() { }
	virtual Base *Copy() const
	{
		puts( "Base::Copy()" );
		return new Base(*this);
	}
};

struct Derived : public Base
{
	Derived *Copy() const
	{
		puts( "Derived::Copy()" );
		return new Derived(*this);
	}
};

int main()
{
	Derived d;
	Base &#38;b = d;
	Base *b2 = b.Copy();
	Base *b3 = d.Copy();
	Derived *d2 = d.Copy();
	Derived *d3 = dynamic_cast( b.Copy() );

	delete b2;
	delete b3;
	delete d2;
	delete d3;
	return 0;
}

The four calls to Copy() will all call Derived::Copy() (as you can see by running the code). This is useful when you need to make full copies of objects and all you have is a Base *.

Edit: This is ignoring the &#60;pre&#62; tags and I don't feel like formatting it using HTML in the 2.5 minutes I have left.</description>
		<content:encoded><![CDATA[<p>Your claim that if the derived class&#8217;s function&#8217;s return type differs from the function it is overriding, then the virtual function will not resolve as intended. This is incorrect. A function&#8217;s return type is not part of its signature. Doing something like the following is actually quite helpful:</p>
<p>#include<br />
struct Base<br />
{<br />
	virtual ~Base() { }<br />
	virtual Base *Copy() const<br />
	{<br />
		puts( &#8220;Base::Copy()&#8221; );<br />
		return new Base(*this);<br />
	}<br />
};</p>
<p>struct Derived : public Base<br />
{<br />
	Derived *Copy() const<br />
	{<br />
		puts( &#8220;Derived::Copy()&#8221; );<br />
		return new Derived(*this);<br />
	}<br />
};</p>
<p>int main()<br />
{<br />
	Derived d;<br />
	Base &amp;b = d;<br />
	Base *b2 = b.Copy();<br />
	Base *b3 = d.Copy();<br />
	Derived *d2 = d.Copy();<br />
	Derived *d3 = dynamic_cast( b.Copy() );</p>
<p>	delete b2;<br />
	delete b3;<br />
	delete d2;<br />
	delete d3;<br />
	return 0;<br />
}</p>
<p>The four calls to Copy() will all call Derived::Copy() (as you can see by running the code). This is useful when you need to make full copies of objects and all you have is a Base *.</p>
<p>Edit: This is ignoring the &lt;pre&gt; tags and I don&#8217;t feel like formatting it using HTML in the 2.5 minutes I have left.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Learn C++ - &#187; 12.1 &#8212; Pointers and references to the base class of derived objects</title>
		<link>http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-14426</link>
		<dc:creator>Learn C++ - &#187; 12.1 &#8212; Pointers and references to the base class of derived objects</dc:creator>
		<pubDate>Mon, 05 May 2008 02:24:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-14426</guid>
		<description>[...] 2007      Prev/Next Posts   &#171; Break Time &#8212; Saint Petersburg &#124; Home &#124; 12.2 &#8212; Virtual functions &#187;     Tuesday, January 29th, 2008 at 3:45 [...]</description>
		<content:encoded><![CDATA[<p>[...] 2007      Prev/Next Posts   &laquo; Break Time &#8212; Saint Petersburg | Home | 12.2 &#8212; Virtual functions &raquo;     Tuesday, January 29th, 2008 at 3:45 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ray</title>
		<link>http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-12520</link>
		<dc:creator>Ray</dc:creator>
		<pubDate>Tue, 22 Apr 2008 12:20:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-12520</guid>
		<description>&lt;pre&gt;Base &#38;rBase = &#038;cDerived;&lt;/pre&gt;
Hi can you explain whats is going on with this line... I'm following well, thx for the tut's! :) just wondering if the first ampersand is meant to be there...?

[ It was a typo.  The line has been fixed.  Thanks for noticing! -Alex ]</description>
		<content:encoded><![CDATA[<pre>Base &amp;rBase = &cDerived;</pre>
<p>Hi can you explain whats is going on with this line&#8230; I&#8217;m following well, thx for the tut&#8217;s! :) just wondering if the first ampersand is meant to be there&#8230;?</p>
<p>[ It was a typo.  The line has been fixed.  Thanks for noticing! -Alex ]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
