运行时绑定 C++

发布于 2024-09-01 12:17:02 字数 122 浏览 5 评论 0原文

我正在阅读有关 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

遥远的绿洲 2024-09-08 12:17:02

这个怎么样? ;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=

严肃地说...第一个 链接 看起来不错。

这是预览:

使用虚函数的最重要原因是在派生类中具有不同的功能。非虚成员函数和虚成员函数的区别在于,非虚成员函数是在编译时解析的。

以及来自另一个网站

在大型、复杂的程序中,虚拟函数可以让程序员简化编程过程。如果使用正确,基类将成功定义其派生类的接口。然而,程序会将这个接口的实现留给派生类。因此,程序员可以使用一个接口来实现多种实现。此功能还允许创建类库,类库建立标准接口,但允许程序员根据可能出现的任何独特实现情况定制这些接口。最流行的库之一是 Microsoft 基础类 (MFC) 库,它提供了在 Windows 环境中进行编程所需的接口。该库使程序员不必重新发明 Windows 界面,而是让他或她专注于这些界面的具体实现。

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:

The most prominent reason why a virtual function will be used is to have a different functionality in the derived class. The difference between a non-virtual member function and a virtual member function is, the non-virtual member functions are resolved at compile time.

And from another site:

In large, complex programs, virtual functions allow the programmer to simplify the programming process. If used correctly, the base class will successfully define the interface of its derived classes. However, the program will leave the implementation of this interface up to the derived classes. Therefore, the programmer can use one interface for multiple implementations. This capability also allows for the creation of class libraries, which establish standard interfaces, but allow the programmer to tailor these interfaces to any unique implementation situations that may arise. One of the most popular libraries around is the Microsoft Foundation Classes (MFC) library, which provides the interfaces necessary for programming in the Windows environment. This library frees the programmer from having to reinvent the Windows interfaces, instead allowing him or her to focus on the specific implementation of these interfaces.

背叛残局 2024-09-08 12:17:02

运行时绑定的最简单形式是多态性。在 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.

聆听风音 2024-09-08 12:17:02

请阅读 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文