第26 - 34行:虚函数。
第二次,进程只是引用数据成员和虚函数。
The second time, the process simply references the data members and virtual functions.
这有效地隐藏了基类中的虚函数。
This effectively hides the virtual function in the base class.
讨论和示例程序都只限于非静态数据成员和虚函数。
The discussion and the sample program are limited to non-static data members and virtual functions.
为什么使用不能用于定义一个虚函数?。
派生类可以有两套虚函数?
你使用虚函数竣工迟绑定。
但是,在某些情况下,不可能使用虚函数。
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.
讨论在派生类中处理私有虚函数的方式的更改。
Discusses changes in the way private virtual functions are handled in derived classes.
编译器用正确的函数地址初始化这些虚函数表。
The compiler initializes these tables with the correct function addresses.
当你通过基类的指针来调用虚函数,技术也是一样的。
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.
现在,我米要调用基类的构造函数,而不是成员函数虚函数。
Now Im going to call virtual function from constructor of Base class rather than member function.
类包含或者继承一个或多个纯虚函数,这样的类就是抽象基类。
A class containing (or inheriting) one or more pure virtual functions is an abstract base class.
发出错误信息,如果有人试图构建一个明确对象或调用虚函数。
The error message is issued if someone tries to explicitly construct an object or call a virtual function.
类函数定义与基类中的虚函数同名,但参数的数目或类型不同。
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.
清单1定义了三个类(A、b和c),它们有一个共同的虚函数whoami 。
Listing 1 defines three classes (a, B and c) with a common virtual function WhoAmI .
当使用虚函数的时候,编译器自动根据对象的实际类型选择正确的函数。
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 main reason for making a virtual function inline is to place its definition in the class, either for convenience or to document its behavior, e. g., for accessors and mutators.
继承层次关系的根类应该定义虚函数性质的析构函数,即使这个析构函数不做任何的事情。
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.
本课程主要内容包括类和对象、关联和聚合、继承、虚函数和多态性、综合设计等相关实验。
This course mainly covers classes and objects, association and aggregation, inheritance, polymorphism, comprehensive design and other related experiments.
本课程主要内容包括类和对象、关联和聚合、继承、虚函数和多态性、综合设计等相关实验。
This course mainly covers classes and objects, association and aggregation, inheritance, polymorphism, comprehensive design and other related experiments.
应用推荐