Effective C++ Item 9 Never call virtual functions during constrution or destruction
2024-10-21 16:05:19
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.
最新文章
- WPF中通过代码设置控件的坐标
- springMVC之<;context:annotation-config />;标签
- Android Studio快捷键每日一练(4)
- DedeCms文档关键词替换,优先替换长尾关键词
- JPA查询语句(转载)
- am335x 更改调试串口
- AS3垃圾回收整理
- Frequent values
- ionic2 使用 cordova 打包成安卓apk
- ReactiveCocoa_v2.5 源码解析之架构总览
- PCL+VS2010环境配置
- IndexedDB,FileSystem- 前端数据库,文件管理系统
- 【JDK1.8】JUC——AbstractQueuedSynchronizer
- Python进阶之面向对象编程
- Linux常用命令——关机重启命令
- Debian Nginx 下载 .apk 文件时候报 403 错误 [1]
- CSS 简介、 选择器、组合选择器
- boost 编写finger服务
- Spring (一)
- 尚学堂java 参考答案 第七章