Because such calls would never go to a more derived class than that of currently executing construtor or destructor. In other word, it would call the version of base class rather than that of derived classes. For example, if you have a base transaction class to log the buy and sell transactions, you may code like this

class Transaction {
public:
Transaction() {
...
logTransaction();
}
virtual void logTransaction();
}; class BugTransaction() : public Transaction {
public:
virtual void logTransaction() const {
...
}
};

  

If you write code like that, you highly possible debug to hell to find out why your derived class method are never called.

Effective C++ Item 9 Never call virtual functions during constrution or destruction的更多相关文章

  1. 条款9:绝不在构造和析构过程中调用virtual函数(Never call virtual functions during construction or destruction)

    NOTE:在构造和析构期间不要调用virtual函数,因为这类调用从不下降至derived class(比起当前执行构造函数和析构函数的那层)

  2. Standard C++ Programming: Virtual Functions and Inlining

    原文链接:http://www.drdobbs.com/cpp/standard-c-programming-virtual-functions/184403747 By Josée Lajoie a ...

  3. [CareerCup] 13.3 Virtual Functions 虚函数

    13.3 How do virtual functions work in C++? 这道题问我们虚函数在C++中的工作原理.虚函数的工作机制主要依赖于虚表格vtable,即Virtual Table ...

  4. [C++] OOP - Virtual Functions and Abstract Base Classes

    Ordinarily, if we do not use a function, we do not need to supply a definition of the function. Howe ...

  5. Effective C++ Item 35 Consider alternatives to virtual functions

    考虑你正在为游戏人物设计一个继承体系, 人物有一个函数叫做 healthValue, 他会返回一个整数, 表示人物的健康程度. 由于不同的人物拥有不同的方式计算他们的健康指数, 将 healthVal ...

  6. 读书笔记 effective c++ Item 31 把文件之间的编译依赖降到最低

    1. 牵一发而动全身 现在开始进入你的C++程序,你对你的类实现做了一个很小的改动.注意,不是接口,只是实现:一个私有的stuff.然后你需要rebuild你的程序,计算着这个build应该几秒钟就足 ...

  7. 读书笔记 effective C++ Item 40 明智而谨慎的使用多继承

    1. 多继承的两个阵营 当我们谈论到多继承(MI)的时候,C++委员会被分为两个基本阵营.一个阵营相信如果单继承是好的C++性质,那么多继承肯定会更好.另外一个阵营则争辩道单继承诚然是好的,但多继承太 ...

  8. Effective C++ Item 36 绝不又一次定义继承而来的 non-virtual 函数

    本文为senlie原创.转载请保留此地址:http://blog.csdn.net/zhengsenlie 经验:绝对不要又一次定义继承而来的 non-virtual 函数 --> Item 7 ...

  9. Effective JavaScript Item 21 使用apply方法调用函数以传入可变參数列表

    本系列作为Effective JavaScript的读书笔记. 以下是一个拥有可变參数列表的方法的典型样例: average(1, 2, 3); // 2 average(1); // 1 avera ...

随机推荐

  1. 【转帖】Sigma水平和缺陷率的对应关系:正态分布中心和1.5标准差偏移

    http://www.pinzhi.org/thread-5395-1-1.html Sigma水平和缺陷率的对应关系:正态分布中心和有1.5个标准差偏移 在过程稳定时,若给出了规范限,过程的平均与标 ...

  2. java web中使用log4j

    测试log4j的项目结构 Log4j.properties的路径为    src/config/log4j Log4j.properties文件的内容 下面定义日志输出级别是 INFO,并且配置了2个 ...

  3. Java 字符串转为字符串数组

    String strSalesStaff_init="李世民,朱元璋,刘秀,李自成"; String[] arrSalesStaff =strSalesStaff_value.sp ...

  4. List<T>做数据源绑定的问题

    List<C_Pinpai> lc;// = new List<C_Pinpai>(); private void BindGrid() { //if (lc.Count &g ...

  5. makefile之wildcard函数

    $(wildcard PATTERN) 函数功能: 获取匹配 PATTERN 的所有对象 返回值: 使用空格分割的匹配对象列表 1. 示例1

  6. SAP ECC6安装系列二:安装前的准备工作

    原作者博客 http://www.cnblogs.com/Michael_z/ ======================================== 安装 Java  1,安装 Java, ...

  7. VBOX Ubuntu设置与Windows的共享文件夹

    参考资料: http://jingyan.baidu.com/article/2fb0ba40541a5900f2ec5f07.html http://zycao.com/virtualbox-ubu ...

  8. django 判断用户是否登陆

    基于类的视图登陆

  9. Hadoop默认端口表及用途

      端口 用途 9000 fs.defaultFS,如:hdfs://172.25.40.171:9000 9001 dfs.namenode.rpc-address,DataNode会连接这个端口 ...

  10. 在sql结果中显示行号

    1.准备 create table newtable ( name ), ) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ); ); ); ); ); 2.实现 ) a ...