pure virtual method called

碰到pure virtual method called,查找了一下资料,记录一下。

pure virtual method calledhttp://bbs.csdn.net/topics/340224117

原因就是在你的纯虚基类的构造函数或者析构函数中调用了纯虚函数,要想找出是调用哪个函数出的问题,你可以在你所有基类的纯虚函数中做一个ASSERT,类似下面的代码
class Base
{
public:
    virtual void foo() = 0  // 这里 = 0 留着,不明白为什么可以这样写就去看C++规范
    {
         ASSERT(FALSE);
    }
};
DEBUG模式下运行,就能定位错误位置了

http://blog.csdn.net/livelylittlefish/article/details/9750593
是谁打印的"pure virtual functioncalled"?
通过strace命令,我们可以清楚地看到程序在core dump之前调用write在标准输出中打印出"pure virtual method called"

http://blog.csdn.net/windzhu0514/article/details/25818779
http://www.artima.com/cppsource/pure_virtual.html

every class with any virtual functions has an array of function pointers, called a "vtbl". Every instance of such as class has a pointer to its class's vtbl, as depicted below.

Figure 1. A class's vtbl points to the class's instance member functions.

If an abstract class with a pure virtual function doesn't define the function, what goes in the corresponding place in the vtbl? Traditionally, C++ implementors have provided a special function, which prints "Pure virtual function called" (or words to that effect), and then crashes the program.

Figure 2. An abstract class's vtbl can have a pointer to a special function.


https://stackoverflow.com/questions/10707286/how-to-resolve-pure-virtual-method-called

猜你喜欢

转载自blog.csdn.net/adaptiver/article/details/78991719