R6025 Pure virtual function call: What is and how to resolve

自作多情 提交于 2019-12-08 06:43:08

问题


Answer can be found here:

An Excerpt from Effective C++, Third Edition, by Scott Meyers

url posted by: hmjd

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

        virtual void     OnRelease() = 0;

by:

        virtual void     OnRelease(){};

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


Original question

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;

    }

At the line

delete pApplication; 

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.

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?

Regards, John

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

EDIT: 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.

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

Thanks, John


回答1:


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.



来源:https://stackoverflow.com/questions/11269035/r6025-pure-virtual-function-call-what-is-and-how-to-resolve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!