Actually i get runtime virtual function call exception.
Scenario is that i have a class Y which is derived from X. Class X has pure
virtual function a() which is implemented in class Y. I have a STL map in
some other class T in which i store pointer to Y against some value. In some
particular scenario, when i fetch pointer to class Y from map and call a(),
pure virtual function call occurs. Moreover, pointer is not NULL.
I delete the pointer from map in destructor of X.
Moreover, this is a multithreaded environment.
"Martin Richter [MVP]" wrote:
[color=blue]
> Hallo pakis!
>[color=green]
> > I am having a problem of pure virtual function call in my project.[/color]
>
> What problems?
>[color=green]
> > Can anyone explaine me the causes of pure virtual function calls other than
> > calling a virtual function in base class?[/color]
>
> A normal call to a member or static function of a class can be directly
> resolved by the compiler and linker. If the this pointer is invalid. the
> correct function will start to execute but the function may crash when
> data via the this pointer is accessed.
>
> A virtual function uses a vtable (a table of pointers to the virtual
> functions), so when calling a virtual function the this pointer must be
> correct because the code that executes a virtual function will fetch the
> address for the function at the proper index of the vtable.
>
> So calling a non-virtual function with the object pointer==NULL is
> possible, but calling a virtual-function with a NULL pointer usually
> causes a crash.
>
> I.e.
> CWnd *pWnd = NULL;
> pWnd->GetSafeHwnd();
> will return FALSE;
> The function checks if the this pointer is false.
> Calling any virtual function of CWnd will immediately crash.
>
> --
> Martin Richter [MVP] WWJD
> "In C we had to code our own bugs. In C++ we can inherit them."
> FAQ :
http://www.mpdvc.de
> Samples:
http://www.codeguru.com http://www.codeproject.com
>[/color]