zoukankan      html  css  js  c++  java
  • pure virtual function call

    2015-04-08 10:58:19

    基类中定义了纯虚函数,派生类中将其实现。

    如果在基类的构造函数或者析构函数中调用了该纯虚函数,

    则会出现R6205 Error: pure virtual function call

    对象在构造时,会先调用基类构造函数,但此时派生类对象还未构造成功,

    因此调用的纯虚函数的虚表指针指向基类的虚表,而基类的纯虚函数没有定义。

    如果是在基类的析构函数中调用,此时的派生类已经被销毁,也会出现这种情况。

     1 #include <stdio.h>
     2 
     3 class Base
     4 {
     5 public:
     6     Base()
     7     {
     8         printf("Base construction be called...\n");
     9         open_func();
    10     }
    11 
    12     void open_func()
    13     {
    14         printf("Base::open_func() be called...\n");
    15         show();
    16     }
    17 
    18     virtual void show() = 0;
    19 };
    20 
    21 class D : public Base
    22 {
    23 public:
    24     D()
    25     {
    26         printf("D construction be called...\n");
    27     }
    28 
    29     void show()
    30     {
    31         printf("D::show() be called...\n");
    32     }
    33 };
    34 
    35 int main()
    36 {
    37     D d;
    38     return 0;
    39 }

  • 相关阅读:
    call,apply和bind的用法及区别
    JavaScript数组去重的方法
    JavaScript原型与原型链
    判断数组的方法
    两栏布局和三栏布局的实现
    小作品
    CSS垂直居中的方法
    闭包实现add(1)(2), add(1,2)的功能
    1.JavaScript的组成
    常用指令
  • 原文地址:https://www.cnblogs.com/felove2013/p/4401812.html
Copyright © 2011-2022 走看看