Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Catching "R6025 - pure virtual function call error" using SEH

Catching "R6025 - pure virtual function call error" using SEH

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chintoo723
    wrote on last edited by
    #1

    I am getting "R6025 - pure virtual function call error" somewhere in my code but I can't seem to catch it using SEH. Is this a known issue with SEH? Here is an example to demonstrate this: #include "stdafx.h" #include /* Compile options needed: none */ class A; void fcn( A* ); class A { public: virtual void f() = 0; A() { fcn( this ); } }; class B : A { void f() { } }; void fcn( A* p ) { p->f(); } // The declaration below invokes class B's constructor, which // first calls class A's constructor, which calls fcn. Then // fcn calls A::f, which is a pure virtual function, and // this causes the run-time error. B has not been constructed // at this point, so the B::f cannot be called. You would not // want it to be called because it could depend on something // in B that has not been initialized yet. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // TODO: Place code here. __try { B b; } __except(EXCEPTION_EXECUTE_HANDLER) { assert (false); } return 0; } thanks!

    M 1 Reply Last reply
    0
    • C Chintoo723

      I am getting "R6025 - pure virtual function call error" somewhere in my code but I can't seem to catch it using SEH. Is this a known issue with SEH? Here is an example to demonstrate this: #include "stdafx.h" #include /* Compile options needed: none */ class A; void fcn( A* ); class A { public: virtual void f() = 0; A() { fcn( this ); } }; class B : A { void f() { } }; void fcn( A* p ) { p->f(); } // The declaration below invokes class B's constructor, which // first calls class A's constructor, which calls fcn. Then // fcn calls A::f, which is a pure virtual function, and // this causes the run-time error. B has not been constructed // at this point, so the B::f cannot be called. You would not // want it to be called because it could depend on something // in B that has not been initialized yet. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // TODO: Place code here. __try { B b; } __except(EXCEPTION_EXECUTE_HANDLER) { assert (false); } return 0; } thanks!

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      An R6025 pure virtual function call error occurs because you've called a pure virtual function - one where you declared

      virtual void MyFunc() = 0;

      The compiler writes the address of a handler function to the slot in the virtual function table corresponding to the function for this class - this handler generates the run-time error. An object whose class has virtual functions carries a virtual function pointer [vfptr] which points to the correct virtual function table [vtable] for the class. During execution of each class's constructor in the hierarchy, from top to bottom (base to derived), the vfptr points to that class, so for example, if you have CBase, CMiddle and CDerived, where CMiddle derives from CBase and CDerived from CMiddle, and you create an instance of CDerived, during CBase's constructor(s) the vfptr points to CBase's vtable, during CMiddle's constructor(s) the vfptr points to CMiddle's vtable, then during CDerived's constructor(s) the vfptr points to CDerived's vtable. Therefore, while the class constructor is executing, if the class has pure virtual functions, the pure virtual function could be called. If you call a pure virtual function within some other function, and call that function from within a constructor, you'll get an R6025 runtime error. Example:

      class CBase
      {
      public:
      virtual void A() = 0;

      CBase()
      {
      B();
      }

      void B()
      {
      // Causes R6025
      A();
      }
      };

      class CDerived : public CBase
      {
      public:
      void A()
      {
      }
      };

      int main(int argc, char* argv[])
      {
      CDerived derived;

      return 0;
      }

      Stability. What an interesting concept. -- Chris Maunder

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups