<?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: 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>
	<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: Ravi Gautam</title>
		<link>http://www.learncpp.com/cpp-tutorial/122-virtual-functions/comment-page-1/#comment-96082</link>
		<dc:creator>Ravi Gautam</dc:creator>
		<pubDate>Tue, 27 Sep 2011 10:22:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-96082</guid>
		<description>If I will use rBase, will it make program run slow?
What other effects will it have?</description>
		<content:encoded><![CDATA[<p>If I will use rBase, will it make program run slow?<br />
What other effects will it have?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/122-virtual-functions/comment-page-1/#comment-96024</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Thu, 15 Sep 2011 06:42:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-96024</guid>
		<description>We use &amp;rbase because we want a reference to the base class, not a shallow copy of the base class.</description>
		<content:encoded><![CDATA[<p>We use &#038;rbase because we want a reference to the base class, not a shallow copy of the base class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ravi Gautam</title>
		<link>http://www.learncpp.com/cpp-tutorial/122-virtual-functions/comment-page-1/#comment-96020</link>
		<dc:creator>Ravi Gautam</dc:creator>
		<pubDate>Wed, 14 Sep 2011 06:53:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-96020</guid>
		<description>Hi,

why are we using &amp;rBase instead of rBase?

I have read the chapter on reference but still can&#039;t figure it out.

Please do reply.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>why are we using &amp;rBase instead of rBase?</p>
<p>I have read the chapter on reference but still can&#8217;t figure it out.</p>
<p>Please do reply.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: D.M. Ryan</title>
		<link>http://www.learncpp.com/cpp-tutorial/122-virtual-functions/comment-page-1/#comment-91714</link>
		<dc:creator>D.M. Ryan</dc:creator>
		<pubDate>Thu, 09 Sep 2010 12:59:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-91714</guid>
		<description>The odd thing is, when I tried your code I got &quot;rDerived is a DerivedTwice&quot;. [I compiled it using Visual Studio 2005.] I thought a second virtual keyword would be needed to get that output, but it isn&#039;t. For VS2005, at least, it&#039;s only necessary for the virtual keyword to be at the base; virtual carries through all the way down the inheritance chin.

To be specific, this code: &lt;pre&gt;class Base
{
protected:

public:
    virtual const char* GetName() { return &quot;Base&quot;; } // virtual keyword here
};

class Derived: public Base
{
public:
   const char* GetName() { return &quot;Derived&quot;; } // note lack of virtual keyword here
};

class DerivedTwice: public Derived
{
public:
    const char* GetName() { return &quot;DerivedTwice&quot;; }
};

int main()
{
    DerivedTwice cDerivedTwice;
    Derived &amp;rDerived = cDerivedTwice;
    cout &lt;&lt; &quot;rDerived is a &quot; &lt;&lt; rDerived.GetName() &lt;&lt; endl; // outputs &quot;rDerived is a DerivedTwice&quot;
                                                            // despite lack of second virtual keyword.

    return 0;
}&lt;/pre&gt;outputs the &quot;rDerived is a DerivedTwice&quot; being looked for, when compiled with VS&#039;05. Other compilers might require the second keyword.</description>
		<content:encoded><![CDATA[<p>The odd thing is, when I tried your code I got &#8220;rDerived is a DerivedTwice&#8221;. [I compiled it using Visual Studio 2005.] I thought a second virtual keyword would be needed to get that output, but it isn&#8217;t. For VS2005, at least, it&#8217;s only necessary for the virtual keyword to be at the base; virtual carries through all the way down the inheritance chin.</p>
<p>To be specific, this code:
<pre>class Base
{
protected:

public:
    virtual const char* GetName() { return &quot;Base&quot;; } // virtual keyword here
};

class Derived: public Base
{
public:
   const char* GetName() { return &quot;Derived&quot;; } // note lack of virtual keyword here
};

class DerivedTwice: public Derived
{
public:
    const char* GetName() { return &quot;DerivedTwice&quot;; }
};

int main()
{
    DerivedTwice cDerivedTwice;
    Derived &amp;rDerived = cDerivedTwice;
    cout &lt;&lt; &quot;rDerived is a &quot; &lt;&lt; rDerived.GetName() &lt;&lt; endl; // outputs &quot;rDerived is a DerivedTwice&quot;
                                                            // despite lack of second virtual keyword.

    return 0;
}</pre>
<p>outputs the &#8220;rDerived is a DerivedTwice&#8221; being looked for, when compiled with VS&#8217;05. Other compilers might require the second keyword.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mystic</title>
		<link>http://www.learncpp.com/cpp-tutorial/122-virtual-functions/comment-page-1/#comment-91682</link>
		<dc:creator>Mystic</dc:creator>
		<pubDate>Wed, 08 Sep 2010 23:35:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-91682</guid>
		<description>&lt;cite&gt;Use of the virtual keyword

Technically, the virtual keyword is not needed in derived class. For example:

&lt;pre&gt;class Base
{
protected:
 
public:
    virtual const char* GetName() { return &quot;Base&quot;; }
};
 
class Derived: public Base
{
public:
    const char* GetName() { return &quot;Derived&quot;; } // note lack of virtual keyword
};
 
int main()
{
    Derived cDerived;
    Base &amp;rBase = cDerived;
    cout &lt;&lt; &quot;rBase is a &quot; &lt;&lt; rBase.GetName() &lt;&lt; endl;
 
    return 0;
}&lt;/pre&gt;
prints

rBase is a Derived&lt;/cite&gt;

What would happen if it was changed to include something like:
&lt;pre&gt;class DerivedTwice: public Derived
{
public:
    const char* GetName() { return &quot;DerivedTwice&quot;; } 
};
 
int main()
{
    DerivedTwice cDerivedTwice;
    Derived &amp;rDerived = cDerivedTwice;
    cout &lt;&lt; &quot;rDerived is a &quot; &lt;&lt; rDerived.GetName() &lt;&lt; endl;
 
    return 0;
}
&lt;/pre&gt;? Then wouldn&#039;t it say &quot;rDerived is a &#039;Derived&#039;&quot; instead of &quot;rDerived is a &#039;DerivedTwice&quot;? That&#039;s not what you&#039;d want... You might want to say something to that effect (if that actually happens, I haven&#039;t checked my code).</description>
		<content:encoded><![CDATA[<p><cite>Use of the virtual keyword</p>
<p>Technically, the virtual keyword is not needed in derived class. For example:</p>
<pre>class Base
{
protected:

public:
    virtual const char* GetName() { return &quot;Base&quot;; }
};

class Derived: public Base
{
public:
    const char* GetName() { return &quot;Derived&quot;; } // note lack of virtual keyword
};

int main()
{
    Derived cDerived;
    Base &amp;rBase = cDerived;
    cout &lt;&lt; &quot;rBase is a &quot; &lt;&lt; rBase.GetName() &lt;&lt; endl;

    return 0;
}</pre>
<p>prints</p>
<p>rBase is a Derived</cite></p>
<p>What would happen if it was changed to include something like:</p>
<pre>class DerivedTwice: public Derived
{
public:
    const char* GetName() { return &quot;DerivedTwice&quot;; }
};

int main()
{
    DerivedTwice cDerivedTwice;
    Derived &amp;rDerived = cDerivedTwice;
    cout &lt;&lt; &quot;rDerived is a &quot; &lt;&lt; rDerived.GetName() &lt;&lt; endl;

    return 0;
}
</pre>
<p>? Then wouldn&#8217;t it say &#8220;rDerived is a &#8216;Derived&#8217;&#8221; instead of &#8220;rDerived is a &#8216;DerivedTwice&#8221;? That&#8217;s not what you&#8217;d want&#8230; You might want to say something to that effect (if that actually happens, I haven&#8217;t checked my code).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: C++ Tutorial and Online Ebook</title>
		<link>http://www.learncpp.com/cpp-tutorial/122-virtual-functions/comment-page-1/#comment-87436</link>
		<dc:creator>C++ Tutorial and Online Ebook</dc:creator>
		<pubDate>Wed, 30 Jun 2010 01:13:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-87436</guid>
		<description>[...] 12.2 Virtual functions [...]</description>
		<content:encoded><![CDATA[<p>[...] 12.2 Virtual functions [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sss</title>
		<link>http://www.learncpp.com/cpp-tutorial/122-virtual-functions/comment-page-1/#comment-86500</link>
		<dc:creator>sss</dc:creator>
		<pubDate>Tue, 15 Jun 2010 07:39:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-86500</guid>
		<description>Hi Alex,

Can you tell me conceptually why the need of virtual functions came into picture? i do understand the concept but what is the necessity, just to reduce overhead ..but calling virtual function itself is an overhead????</description>
		<content:encoded><![CDATA[<p>Hi Alex,</p>
<p>Can you tell me conceptually why the need of virtual functions came into picture? i do understand the concept but what is the necessity, just to reduce overhead ..but calling virtual function itself is an overhead????</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raj Sodhi</title>
		<link>http://www.learncpp.com/cpp-tutorial/122-virtual-functions/comment-page-1/#comment-85743</link>
		<dc:creator>Raj Sodhi</dc:creator>
		<pubDate>Tue, 01 Jun 2010 06:41:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-85743</guid>
		<description>Hello Alex,

Wonderful explanations all around.  
Way better than most textbooks.

Only one point that has confused the daylights out of me.

&lt;pre&gt;

15. int  main()
16. {
17.    Derived cDerived;
18.    Base &amp;rBase = &amp;cDerived;
19.    cout &lt;&lt; &quot;rBase is a &quot; &lt;&lt; rBase.GetName() &lt;&lt; endl;
20. 
21.    return 0; }
&lt;!--formatted--&gt;&lt;/pre&gt;


I believe rBase is a &quot;reference&quot;, not a &quot;pointer.&quot;
if it were 
&lt;pre&gt;
18.    Base *rBase = &amp;cDerived;
&lt;!--formatted--&gt;&lt;/pre&gt;
Then it would be a pointer.

Thanks!

Raj</description>
		<content:encoded><![CDATA[<p>Hello Alex,</p>
<p>Wonderful explanations all around.<br />
Way better than most textbooks.</p>
<p>Only one point that has confused the daylights out of me.</p>
<pre>

15. int  main()
16. {
17.    Derived cDerived;
18.    Base &amp;rBase = &amp;cDerived;
19.    cout &lt;&lt; &quot;rBase is a &quot; &lt;&lt; rBase.GetName() &lt;&lt; endl;
20.
21.    return 0; }
<!--formatted--></pre>
<p>I believe rBase is a &#8220;reference&#8221;, not a &#8220;pointer.&#8221;<br />
if it were </p>
<pre>
18.    Base *rBase = &amp;cDerived;
<!--formatted--></pre>
<p>Then it would be a pointer.</p>
<p>Thanks!</p>
<p>Raj</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: auasp</title>
		<link>http://www.learncpp.com/cpp-tutorial/122-virtual-functions/comment-page-1/#comment-85597</link>
		<dc:creator>auasp</dc:creator>
		<pubDate>Sun, 30 May 2010 04:10:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-85597</guid>
		<description>a very good article about vitual functions is here:
http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/language/ref/cplr139.htm</description>
		<content:encoded><![CDATA[<p>a very good article about vitual functions is here:<br />
<a href="http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/language/ref/cplr139.htm" rel="nofollow">http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/language/ref/cplr139.htm</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: auasp</title>
		<link>http://www.learncpp.com/cpp-tutorial/122-virtual-functions/comment-page-1/#comment-85570</link>
		<dc:creator>auasp</dc:creator>
		<pubDate>Sat, 29 May 2010 15:36:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/122-virtual-functions/#comment-85570</guid>
		<description>one extra &#039;&amp;&#039; in line number 18 of 2nd code listing</description>
		<content:encoded><![CDATA[<p>one extra &#8216;&amp;&#8217; in line number 18 of 2nd code listing</p>
]]></content:encoded>
	</item>
</channel>
</rss>

