运行时绑定 C++
我正在阅读有关 C++ 中的虚拟函数的教科书,并且我的书没有详细说明运行时绑定到底是什么。它没有给我任何关于为什么需要运行时绑定的信息。
也许 SO 的好心人可以为我提供一些链接或信息?
谢谢 :]
I'm reading in my text book about virtual functions in C++ and my book doesn't elaborate on what exactly run-time binding is. It doesn't give me any information as to why I would need run-time binding.
Maybe the nice people at SO can provide me with some links or information?
Thanks :]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这个怎么样? ;D
http://www.google.ca/search?hl=en&source=hp&q=virtual+function+runtime+binding+c %2B%2B&aq=f&aqi=&aql=&oq=&gs_rfai=
严肃地说...第一个 链接 看起来不错。
这是预览:
以及来自另一个网站:
How about this one? ;D
http://www.google.ca/search?hl=en&source=hp&q=virtual+function+runtime+binding+c%2B%2B&aq=f&aqi=&aql=&oq=&gs_rfai=
In all seriousness though... the first link looks decent.
Here's a preview:
And from another site:
运行时绑定的最简单形式是多态性。在 C++ 上下文中,多态性是通过虚函数实现的。其基本目的是通过指针或对基类的引用来调用派生类实例上的方法。
谷歌搜索虚拟函数应该会给你很多关于如何以及为什么这样做的好结果。
The simplest form of run-time binding is polymorphism. In context of C++ polymorphism is achieved through virtual functions. The basic purpose of this is to call methods on instances of derived classes through a pointer or a reference to a base class.
Googling virtual functions should give you plenty of good results on how and why to do this.
请阅读 Uncle Bobs 关于面向对象设计的 SOLID 原则的文章:http://butunclebob.com/ArticleS。 UncleBob.PrinciplesOfOod
显然,它们与运行时绑定无关,但它们确实描述了您正在尝试解决的需要使用运行时绑定的设计问题类型。
我认为关于开闭原则的文章可能最好地演示了(同样,本文不是关于运行时绑定的)您何时需要这样做:
http://www.objectmentor.com/resources/articles/ocp.pdf
Please read Uncle Bobs articles on the SOLID principles of Object Orientated Design: http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
Obviously, they are not about run time binding but they do describe the type of design problems that you are trying to solve which require to use run time binding.
I think the article on the open closed principle brobably best demonstrates (again, the article isn't about run time binding)when you would need to do this:
http://www.objectmentor.com/resources/articles/ocp.pdf