How to debug "pure virtual function call"

lsmgms
lsmgms used Ask the Experts™
on
Hi,

I am using mpatrol to debug memory corruption and it reported this error:

Runtime Error!
  Program: ...\pwlib\lib\asnparser.exe
  R6025
  - pure virtual function call

This message does not provide any info for me to debug.
Unfortunately I cannot run under debugger(mpatrol will complain this: HEAP[asnparser.exe]: Invalid Address specified to RtlSizeHeap( b90000, ba1c40 )).

Any idea?

Thanks

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Provide the pure virtual function a body in the absolute base class and put an assert statement. Code below:
class Base //abstract base class
{
   Base();
   virtual ~Base();
   virtual BOOL PureVirtualCall(void) = 0;
};

class Derived : public Base
{
   Derived();
   ~Derived();
   BOOL PureVirtualCall(void)
   {
     cout << "I am in Derived class here";
   }
};

//in cpp file
BOOL Base::PureVirtualCall(void)
{
  //if this is called implies a pure virtual function has been called
   cout << "Unexpected pure virtual function called";
   assert(0);
   return TRUE;
}


P.S. You may have to put such statements at all pure virtual functions body to get to the call that is causing the problem

Commented:
If its a 3rd party thing than it means its a bug in their code and u can do nothing about it.
If its yours, see the above comment as a possible solution or use try-catch to fetch the error...

Author

Commented:
Hi vbk_bgm,

This method does not work. The pointer does not in vtable although it has implementation.  I use the following codes to test:

#include <iostream>
using namespace std;

typedef void(*Fun)();

class Base {
public:
  Base() {
    cout << "In Base" << endl;
    cout << "Virtual Pointer = " 
         << (int*)this << endl;
    cout << "Address of Vtable = " 
         << (int*)*(int*)this << endl;
    cout << "Value at Vtable 1st entry = " 
         << (int*)*((int*)*(int*)this+0) << endl;
    cout << "Value at Vtable 2nd entry = " 
         << (int*)*((int*)*(int*)this+1) << endl;
   
    // try to execute first virtual function
    Fun pFun = (Fun)*((int*)*(int*)this+0);
    pFun();

    cout << endl;
  }
  virtual void f1() = 0;
  virtual void f2() = 0;
};

void Base::f1()
{
     cout << "Base::f1()" << endl;
}

void Base::f2()
{
     cout << "Base::f2()" << endl;
}


class Drive : public Base {
public:
  Drive() {
    cout << "In Drive" << endl;
    cout << "Virtual Pointer = " 
         << (int*)this << endl;
    cout << "Address of Vtable = " 
         << (int*)*(int*)this << endl;
    cout << "Value at Vtable 1st entry = " 
         << (int*)*((int*)*(int*)this+0) << endl;
    cout << "Value at Vtable 2nd entry = " 
         << (int*)*((int*)*(int*)this+1) << endl;
    cout << endl;
  }
  virtual void f1() { cout << "Drive::f1" << endl; }
  virtual void f2() { cout << "Drive::f2" << endl; }
};


int main() {
  Drive d;

  return 0;
}

HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Author

Commented:
By the way, I have found up the way to debug it.  When the run-time error message box appears, run WinDbg and attach to the process, and then select call stack.  The WinDbg will keep waiting until message box is closed.  The call stack will then show the stacks.

Regards

Commented:
This question didn't show any activity for more than 21 days. I will ask Community Support to close it unless you finalize it yourself within 7 days.
You can always request to keep this question open. But remember, experts can only help if you provide feedback to their comments.
Unless there is objection or further activity,  I will suggest to

    "refund the points and delete this question"

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
========
Werner
PAQ'd and points refunded.

SpideyMod
Community Support Moderator @Experts Exchange

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial