R6025纯虚函数调用:什么是如何解决 [英] R6025 Pure virtual function call: What is and how to resolve

查看:701
本文介绍了R6025纯虚函数调用:什么是如何解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

回答可以在这里找到


有效C ++的摘录,第三版,Scott Meyers

发布的网址: hmjd

请阅读该页面,以便了解为什么会发生。你也知道为什么要替换

Please read that page so you understand why it is happening. Also you know why substituting

        virtual void     OnRelease() = 0;

由:

        virtual void     OnRelease(){};

会工作,但不是正确的解决方法。

will work but isn't the correct way to resolve.

原始问题

R6025:纯虚函数调用

R6025: pure virtual function call

#include <Windows.h>

// static lib
    //file.h
    class cBaseApplication
    {
    public:
        virtual          ~cBaseApplication(){ Release(); }
        virtual void     Release()
                         {

                             OnRelease();

                         };
        virtual void     OnRelease() = 0;
    }; // class cBaseApplication

    //file1.h
    class cApplication : public cBaseApplication
    {
    public:
        virtual void     OnRelease()
                         {

                             /* what the heck do something here */

                         };
    }; // class cApplication

// executable
    // file3.h
    int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow )
    {

        cApplication* pApplication = new cApplication();

        /*...what the heck, do stuff...*/

        pApplication->Release();
        delete pApplication;      // R6025: pure virtual function call
        pApplication = NULL;

        return 0;

    }

在行

delete pApplication; 

R6025发生,当删除时,所有精细但内存泄漏发生。
当cApplication应用程序将被销毁时,删除指针引用R6025也会在程序退出上发生。

R6025 occurs and when removing, all fine but memory leaks occur. Removing the pointer reference the R6025 will happen too on 'program exit' when cApplication application will be destruct.

由于嘟嘟声,R6025吓唬我:

Due to the beep, the R6025 scares me :s

似乎我必须在两者之间选择,但我只是不想要,这里发生了什么?

As it seems I have to choose between the two but I just don't want to, what is happening here?

注意,
约翰

编辑:添加了一些代码,似乎Eran是正确的,因为我在那里调用虚函数

Added some code, seems Eran is right as I do call virtual functions there

编辑:添加到示例,[virtual void OnLostDevice()= 0; ]。从抽象到替代提供了一个立即的解决方案。在下面的评论中开始阅读该页面,因为我得到的感觉我还没有。

Added to example, [ virtual void OnLostDevice() = 0; ]. Changing from abstract to ascoop gave an immediate solution. Starting to read that page in the comments below as I got the feeling I ain't there yet.

编辑:在我得到答案后,我明白我自己的问题。

After I got the answer I understood my own problem. So I rewrote the question, so the answer fits the question.

感谢,John

推荐答案

您不能在析构函数中的构造函数中调用虚函数。我在这里没有看到一个纯虚函数,但如果 cBaseApplication :: Release 偶然调用一个,你会得到这个错误每次你毁了一个 cBaseApplication 。我不确定是这个问题,因为我没有所有的代码,但你的代码调用这种问题。

You must not call virtual functions in constructors and in destructors. I don't see a pure virtual function here, but if cBaseApplication::Release happen to call one, you'll get that error every time you destruct a cBaseApplication. I'm not sure that's the issue because I don't have all the code, but your code calls for that kind of issues.

这篇关于R6025纯虚函数调用:什么是如何解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆