Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top