<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>virtual and pure virtual function in c++ - Wikitechy</title>
	<atom:link href="https://www.wikitechy.com/interview-questions/tag/virtual-and-pure-virtual-function-in-c/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.wikitechy.com/interview-questions/tag/virtual-and-pure-virtual-function-in-c/</link>
	<description>Interview Questions</description>
	<lastBuildDate>Fri, 19 Aug 2022 12:34:29 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.wikitechy.com/interview-questions/wp-content/uploads/2025/10/cropped-wikitechy-icon-32x32.png</url>
	<title>virtual and pure virtual function in c++ - Wikitechy</title>
	<link>https://www.wikitechy.com/interview-questions/tag/virtual-and-pure-virtual-function-in-c/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>What are Virtual functions in C++ ?</title>
		<link>https://www.wikitechy.com/interview-questions/cpp/what-are-virtual-functions-in-cpp/</link>
					<comments>https://www.wikitechy.com/interview-questions/cpp/what-are-virtual-functions-in-cpp/#respond</comments>
		
		<dc:creator><![CDATA[webmaster]]></dc:creator>
		<pubDate>Fri, 19 Aug 2022 12:34:29 +0000</pubDate>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[advantages of virtual function in c++]]></category>
		<category><![CDATA[C++ virtual function]]></category>
		<category><![CDATA[C++ Virtual Functions]]></category>
		<category><![CDATA[virtual and pure virtual function in c++]]></category>
		<category><![CDATA[virtual class in c++]]></category>
		<category><![CDATA[virtual function example]]></category>
		<category><![CDATA[Virtual Function in C++]]></category>
		<category><![CDATA[what is pure virtual function in c++]]></category>
		<category><![CDATA[what is virtual function]]></category>
		<category><![CDATA[Why do we need virtual functions in C++?]]></category>
		<guid isPermaLink="false">https://www.wikitechy.com/interview-questions/?p=4820</guid>

					<description><![CDATA[Virtual function is a member function which is re-defined by a derived class and declared within a base class. When you refer to a derived class object using a reference or pointer to the base class, you can call a virtual function for that object and execute the derived class’s version of the function. It [&#8230;]]]></description>
										<content:encoded><![CDATA[<ul>
<li style="text-align: justify;">Virtual function is a member function which is re-defined by a derived class and declared within a base class.</li>
<li style="text-align: justify;">When you refer to a derived class object using a reference or pointer to the base class, you can call a virtual function for that object and execute the derived class’s version of the function.</li>
<li style="text-align: justify;">It ensures that the correct function is called for an object, regardless of the type of reference used for function call.</li>
<li style="text-align: justify;">It is mainly used to achieve Run-time polymorphism.</li>
<li style="text-align: justify;">In base class functions are declared with a <strong>virtual. </strong>At run time the resolving of function call is done.</li>
</ul>
<h2 id="sample-code" style="text-align: justify;">Sample Code</h2>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-cpp code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-cpp code-embed-code">using namespace std;<br/> <br/>class base {<br/>public:<br/>    virtual void print()<br/>    {<br/>        cout &lt;&lt; &quot;print base class\n&quot;;<br/>    }<br/> <br/>    void show()<br/>    {<br/>        cout &lt;&lt; &quot;show base class\n&quot;;<br/>    }<br/>};<br/> <br/>class derived : public base {<br/>public:<br/>    void print()<br/>    {<br/>        cout &lt;&lt; &quot;print derived class\n&quot;;<br/>    }<br/> <br/>    void show()<br/>    {<br/>        cout &lt;&lt; &quot;show derived class\n&quot;;<br/>    }<br/>};<br/> <br/>int main()<br/>{<br/>    base *bptr;<br/>    derived d;<br/>    bptr = &amp;d;<br/> <br/>    // Virtual function, binded at runtime<br/>    bptr-&gt;print();<br/> <br/>    // Non-virtual function, binded at compile time<br/>    bptr-&gt;show();<br/>   <br/>    return 0;<br/>}</code></pre> </div>
<h2 id="output" style="text-align: justify;">Output</h2>
<p style="text-align: justify;"><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-4821" src="https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/virtual-function.png" alt="" width="875" height="162" srcset="https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/virtual-function.png 875w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/virtual-function-300x56.png 300w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/virtual-function-768x142.png 768w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/virtual-function-390x72.png 390w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/virtual-function-820x152.png 820w" sizes="(max-width: 875px) 100vw, 875px" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/cpp/what-are-virtual-functions-in-cpp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
