Q: What is virtual function?
A: A virtual function or virtual method is a function or method whose behavior can be overridden within an inheriting class by a function with the same signature. This concept is an important part of the polymorphism portion of object-oriented programming (OOP)

Q: What is a "pure virtual" member function?
A: The abstract class whose pure virtual method has to be implemented by all the classes which derive on these. Otherwise it would result in a compilation error. This construct should be used when one wants to ensure that all the derived classes implement the method defined as pure virtual in base class.

Q: How virtual functions are implemented C++?

A: Virtual functions are implemented using a table of function pointers, called the vtable. There is one entry in the table per virtual function in the class. This table is created by the constructor of the class. When a derived class is constructed, its base class is constructed _rst which creates the vtable. If the derived class overrides any of the base classes virtual functions, those entries in the vtable are overwritten by the derived class constructor. This is why you should never call virtual functions from a constructor: because the vtable entries for the object may not have been set up by the derived class constructor yet, so you might end up calling base class implementations of those virtual functions

(C/C++ )Interview in English - Virtual的更多相关文章

  1. (C++) Interview in English. - Constructors/Destructors

    Constructors/Destructors. 我们都知道,在C++中建立一个类,这个类中肯定会包括构造函数.析构函数.复制构造函数和重载赋值操作:即使在你没有明确定义的情况下,编译器也会给你生成 ...

  2. (C/C++) Interview in English - Basic concepts.

    Question Key words Anwser A assignment operator abstract class It is a class that has one or more pu ...

  3. (C/C++) Interview in English - Class

    Q: What is a class? A: A class is an expanded concept of a data structure: instead of holding only d ...

  4. (C/C++) Interview in English - Threading

    Q. What's the process and threads and what's the difference between them? A.  A process is an execut ...

  5. (C/C++) Interview in English - Points.

    Q: What is a dangling pointer? A: A dangling pointer arises when you use the address of an object af ...

  6. (C/C++) Interview in English. - Memory Allocation/Deallocation.

    Q: What is the difference between new/delete and malloc/free? A: Malloc/free do not know about const ...

  7. step 1:begin to identify something in english(to becaome a baby again)

    long long ago , i think if i want to improve my english especially computer english . i must do so m ...

  8. c++设计模式:模板模式

    模板模式和策略模式的区别: 模板方法模式的主要思想:定义一个算法流程,将一些特定步骤的具体实现.延迟到子类.使得可以在不改变算法流程的情况下,通过不同的子类.来实现“定制”流程中的特定的步骤. 策略模 ...

  9. C# Interview Questions:C#-English Questions

    This is a list of questions I have gathered from other sources and created myself over a period of t ...

随机推荐

  1. 2层Folder删除问题,父文件夹删不掉

    在此用的是由内向外删除.文件结构是:父文件夹/子文件夹/文件.用的是java1.6的java.io.FIle#deleteFile(); 在删除的过程中,发现,文件删除的时候没有问题,但是在子文件夹删 ...

  2. linux 网络协议分析---3

    本章节主要介绍linxu网络模型.以及常用的网络协议分析以太网协议.IP协议.TCP协议.UDP协议 一.网络模型 TCP/IP分层模型的四个协议层分别完成以下的功能: 第一层 网络接口层 网络接口层 ...

  3. leetcode 135. Candy ----- java

    There are N children standing in a line. Each child is assigned a rating value. You are giving candi ...

  4. WinMain初始化详细过程以及消息循环

    主要内容:详细介绍WinMain函数的初始化过程以及消息循环 1.窗口类定义 通过给窗口类数据结构WNDCLASS赋值完成, 该数据结构中包含窗口类的各种属性 <1>LoadIcon 作用 ...

  5. scala言语基础学习九

    模式匹配 case _ =>不能放在函数的中间必须放在最后,否则scala会编译不通过 在case 里面使用if守卫 在模式匹配中获取输入的数据(在匹配不到的情况下) 对类型进行匹配 case ...

  6. Dijkstra + 优先队列优化 模板

    #include <cstdio> #include <cstring> #include <queue> #include <vector> #inc ...

  7. Linux系统编程@多线程编程(二)

    线程的操作 线程标识 线程的ID表示数据类型:pthread_t (内核中的实现是unsigned long/unsigned int/指向pthread结构的指针(不可移植)几种类型) 1.对两个线 ...

  8. 系统镜像以及微PE工具箱

    微PE地址:http://www.wepe.com.cn/download.html MSDN镜像下载地址:http://msdn.itellyou.cn/ 小白也能轻松装系统(win10 64位) ...

  9. java 动态代码生成。

    http://stackoverflow.com/questions/2320404/creating-classes-dynamically-with-java https://zeroturnar ...

  10. Linux-同步异步非阻塞阻塞的解析

    一.理解同步.异步.阻塞.非阻塞 出场人物:老张,水壶两把(普通水壶,简称水壶:会响的水壶,简称响水壶). 1 老张把水壶放到火上,立等水开.(同步阻塞) 老张觉得自己有点傻. 2 老张把水壶放到火上 ...