<?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</title>
	<atom:link href="https://www.aitaocui.cn/tag/137302/feed" rel="self" type="application/rss+xml" />
	<link>https://www.aitaocui.cn</link>
	<description>翡翠玉石爱好者聚集地</description>
	<lastBuildDate>Tue, 22 Nov 2022 04:26:57 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.1</generator>

<image>
	<url>https://www.aitaocui.cn/wp-content/uploads/2022/11/taocui.png</url>
	<title>virtual</title>
	<link>https://www.aitaocui.cn</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>virtual(定义C++中虚函数的关键字)</title>
		<link>https://www.aitaocui.cn/article/217024.html</link>
					<comments>https://www.aitaocui.cn/article/217024.html#respond</comments>
		
		<dc:creator><![CDATA[朱玉婷]]></dc:creator>
		<pubDate>Tue, 22 Nov 2022 04:26:57 +0000</pubDate>
				<category><![CDATA[百科]]></category>
		<category><![CDATA[virtual]]></category>
		<guid isPermaLink="false">https://www.aitaocui.cn/?p=217024</guid>

					<description><![CDATA[virtual是定义C++中虚函数的关键字,这种函数或方法可以被子类继承和覆盖，通常使用动态调度实现。在面向对象程序设计领域，C++、ObjectPascal等语言中有虚函数（英语...]]></description>
										<content:encoded><![CDATA[</p>
<article>
<p>virtual是定义C++中虚函数的关键字,这种函数或方法可以被子类继承和覆盖，通常使用动态调度实现。在面向对象程序设计领域，C++、ObjectPascal等语言中有虚函数（英语：virtualfunction）或虚方法（英语：virtualmethod）的概念。这一概念是面向对象程序设计中（运行时）多态的重要组成部分。</p>
<p>简言之，虚函数可以给出目标函数的定义，但该目标的具体指向在编译期可能无法确定。虚函数在设计模式方面扮演重要角色。例如，《设计模式》一书中提到的23种设计模式中，仅5个对象创建模式就有4个用到了虚函数（抽象工厂、工厂方法、生成器、原型），只有单例没有用到。</p>
</article>
<article>
<h1>英语翻译</h1>
<p>adj.实质上的，事实上的；（计算机）虚拟的；&lt;物&gt;有效的，虚像的；（粒子）实际存在的物。</p>
<h1>目的</h1>
<p>在面向对象程序设计中，派生类继承自基类。使用指针或引用访问派生类对象时，指针或引用本身所指向的类型可以是基类而不是派生类。如果派生类覆盖了基类中的方法，通过上述指针或引用调用该方法时，可以有两种结果：</p>
<ol style="list-style-type:decimal">
<li>
<div>调用到基类的方法：编译器根据指针或引用的类型决定，称作“早绑定”。</div>
</li>
</ol>
<p>2.调用到派生类的方法：语言的运行时系统根据对象的实际类型决定，称作“迟绑定”。</p>
<p>虚函数的效果属于后者。如果问题中基类的函数是“虚”的，则调用到的都是最终派生类（英语：most-derivedclass）中的函数实现，与指针或引用的类型无关。反之，如果函数非“虚”，调用到的函数就在编译期根据指针或者引用所指向的类型决定。有了虚函数，程序甚至能够调用编译期还不存在的函数。</p>
<p>在C++中，在基类的成员函数声明前加上关键字virtual即可让该函数成为虚函数，派生类中对此函数的不同实现都会继承这一修饰符，允许后续派生类覆盖，达到迟绑定的效果。即便是基类中的成员函数调用虚函数，也会调用到派生类中的版本。</p>
</article>
<div class="mt-3 mb-3" style="max-width: 770px;height: auto;">
                                    </div>
<div class="mt-3 mb-3" style="max-width: 770px;height: auto;">
                                    </div>
<div class="mt-3 mb-3" style="max-width: 770px;height: auto;">
                                    </div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.aitaocui.cn/article/217024.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
