Hallo pakis!
I am having a problem of pure virtual function call in my project.
What problems?
Can anyone explaine me the causes of pure virtual function calls other than
calling a virtual function in base class?
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