第26 - 34行:虚函数。
虚函数简单地向标准输出写一行文本。
The virtual functions simply write a line of text to standard output.
第二次,进程只是引用数据成员和虚函数。
The second time, the process simply references the data members and virtual functions.
为纯虚函数所生成的代码如列表1 中所示。
The code generated for the pure virtual function is shown in Listing 1.
讨论和示例程序都只限于非静态数据成员和虚函数。
The discussion and the sample program are limited to non-static data members and virtual functions.
虚函数是实现动态多态性的方法。
Virtual Function is the method to realize dynamic polymorphism.
这有效地隐藏了基类中的虚函数。
This effectively hides the virtual function in the base class.
派生类可以有两套虚函数?
但是,在某些情况下,不可能使用虚函数。
In some situations however, the use of virtual functions is not possible.
在头文件中为该虚函数所生成的代码如列表2中所示。
The code generated for the virtual function in a header file is shown in Listing 2.
派生类继承虚拟基类的虚函数的多个重写。
The derived class inherits more than one override of a virtual function of a virtual base class.
这个例子的性能和纯虚函数表例子是相同的。
The performance of this sample and the pure vtable-based sample are exactly identical.
讨论在派生类中处理私有虚函数的方式的更改。
Discusses changes in the way private virtual functions are handled in derived classes.
这个函数是一个真正的消息句柄,不是虚函数。
This function is really a message handler, not a virtual function.
编译器用正确的函数地址初始化这些虚函数表。
The compiler initializes these tables with the correct function addresses.
首先,你应该知道什么是虚函数,以及如何使用它。
Firstly, you should know what a virtual function is, and how to use it.
如果某虚函数为私有函数,则派生类型无法访问它。
If a virtual function is private, it cannot be accessed by a derived type.
当你通过基类的指针来调用虚函数,技术也是一样的。
When you invoke calls through a pointer to the base class, the technique is the same.
这样,使用虚函数的对象每个实例占用4个额外的字节。
Thus an object that USES virtual functions occupies 4 additional bytes for each instance.
类包含或者继承一个或多个纯虚函数,这样的类就是抽象基类。
A class containing (or inheriting) one or more pure virtual functions is an abstract base class.
类函数定义与基类中的虚函数同名,但参数的数目或类型不同。
A class function definition has the same name as a virtual function in a base class but not the same number or type of arguments.
所谓虚类或虚函数是指应用程序以后需要,但是目前还没写的代码。
A virtual class or function is code that the application will eventually need, but it isn't written yet.
当使用虚函数的时候,编译器自动根据对象的实际类型选择正确的函数。
When we use virtual functions, the compiler automatically selects the right function according to the actual type of the object.
如果函数用作静态成员函数,则重命名该函数,以便不与基类虚函数冲突。
If the function was intended to be a static member function, rename it so it doesn't conflict with the base class virtual function.
继承层次关系的根类应该定义虚函数性质的析构函数,即使这个析构函数不做任何的事情。
The root class of an inheritance hierarchy should define a virtual destructor even if the destructor has no work to do.
客户端或服务器端最重要的部分是虚函数NotifyReceivedPackage,定义如下。
The most important part of the client or server code is the virtual function NotifyReceivedPackage, as described below.
使用动态强制类型转换要小心。只要有可能,定义和使用虚函数比直接接管类型管理好得多。
Dynamic casts should be used with caution. Whenever possible, it is much better to define and use a virtual function rather than to take over managing the types directly.
子对象多重继承自多个基类,每个基类都有虚函数,那么子类对象的内存布局是什么样的?
A function that is virtual in a base class is implicitly virtual in its derived classes. When a derived class overrides a virtual, the parameters in the base and derived classes must match exactly.
首先,Vee -Table指针用于访问虚函数,而对数据成员的访问直接使用编译时偏移量实现。
First, the Vee-Table pointer is used to access virtual functions, and data members are accessed directly using compile time offsets.
首先,Vee -Table指针用于访问虚函数,而对数据成员的访问直接使用编译时偏移量实现。
First, the Vee-Table pointer is used to access virtual functions, and data members are accessed directly using compile time offsets.
应用推荐