Pure Virtual Function Called: An Explanation
来源:互联网 发布:vue.js filter用法 编辑:程序博客网 时间:2024/05/14 14:58
Summary
"Pure virtual function called" is the dying message of the occasional crashed C++ program. What does it mean? You can find a couple of simple, well-documented explanations out there that apply to problems easy to diagnose during postmortem debugging. There is also another rather subtle bug that generates the same message. If you have a mysterious crash associated with that message, it might well mean your program went indirect on a dangling pointer. This article covers all these explanations.......
Build 'em Up, Tear 'em Down
When you construct an instance of a derived class, what happens, exactly? If the class has avtbl, the process goes something like the following.
Step 1: Construct the top-level base part:.
- Make the instance point to the base class's vtbl.
- Construct the base class instance member variables.
- Execute the body of the base class constructor.
Step 2: Construct the derived part(s) (recursively):
- Make the instance point to the derived class's vtbl.
- Construct the derived class instance member variables.
- Execute the body of the derived class constructor.
Destruction happens in reverse order, something like this:
Step 1: Destruct the derived part:
- (The instance already points to the derived class's vtbl.)
- Execute the body of the derived class destructor.
- Destruct the derived class instance member variables.
Step 2: Destruct the base part(s) (recursively):
- Make the instance point to the base class's vtbl.
- Execute the body of the base class destructor.
- Destruct the base class instance member variables.
附实例:
#include <iostream>class Base{public:virtual ~Base(){std::cout<<"Base::~Base()"<<std::endl;sleep(30);}virtual void do_sth() = 0;};class Derived: public Base{public:virtual ~Derived(){std::cout<<"Derived::~Derived()"<<std::endl;}virtual void do_sth(){std::cout<<"Derived::do_sth()"<<std::endl;}};void* mydo(void *p){sleep(10);Base * _p = (Base*) p;_p->do_sth();}int main(){Base * pb = new Derived();pthread_t thread;pthread_create(&thread,NULL,mydo,pb);delete pb;sleep(10000);return 0;}
原文链接:"Pure Virtual Function Called": An Explanation
- "Pure Virtual Function Called": An Explanation
- Pure Virtual Function Called: An Explanation
- "Pure Virtual Function Called": An Explanation
- Pure virtual function called
- pure virtual function called
- Pure Virtual Function Called
- Pure virtual function called
- C++: Pure Virtual Function Called
- 结合实例详解"pure Virtual function called"
- The error “Pure Virtual Function Called” about C++
- pure virtual function called--虚函数调用错误
- pure virtual function called--虚函数调用错误
- pure virtual method called
- C++ virtual function explanation
- pure virtual function call
- 【转载】一篇详尽分析C++“Pure Virtual Function Called”错误的文章
- "Pure Virtual Function Called" 纯虚函数调用错误分析(翻译)
- C++ virtual function (not pure virtual function)
- Maven实战(六)依赖
- 栈的压入压出(判断栈的压出顺序是否合法)
- ocr资料备忘
- C++ string 详解(转载)
- Android---实现登录用户信息保存
- Pure Virtual Function Called: An Explanation
- Hoj 1356 Prime Judge
- The 9th tip of SQL design by DB Query Analyzer
- POJ1664(放苹果,感觉比较有意思)
- serializable
- hdu 1028 Ignatius and the Princess III
- 如何让 Eclipse Java EE 版安装 CDT 以同时支持 Java 和 C/C++ 开发
- mssql 的映像劫持命令
- 《德鲁克管理思想精要》读书笔记2 - 企业的宗旨、目标