The following article refers to C++ specific programming constructs, and
Microsoft Visual C++ specific compiler options.
The __purecall function (C++)
The __purecall function is a special function (defined with
C linkage) that is defined in the default run-time library, and may be
called at run time if there is an error referencing an object's
virtual function table. This will usually happen as a result of a program
error. The following code causes this error:
struct A;
void x(A*);
struct A
{
virtual void f() = 0;
A() { x(this); }
};
struct B : A
{
void f() { }
};
void x(A*p) { p->f(); }
void main()
{
B aB; // calls B::B calls A::A calls
} // x calls A::f (pure virtual function)
Because such errors cannot be caught at compile time, the __purecall
function is called, generating the following run-time error:
runtime error R6025
- pure virtual function call
If an application (such as a device driver) must be compiled without
using the standard run-time libraries (compiler option /Zl or linker option
/NODEFAULTLIB), but requires virtual function calls, you will get an
"undefined symbol" linker error on __purecall. You can work around this
error in one of two ways:
Define your own __purecall function and compile with the /Gd
option (specify __cdecl calling convention). The following is a minimal
example:
int __purecall( void )
{
/* insert your own error reporting code here */
return 0;
}
If __purecall is redefined in exactly this way, no run time error
is generated if the user calls a pure virtual function. The custom
__purecall function should contain appropriate error checking and
recovery code, (for example, calling _exit or printing a fatal error
message) as noted in the sample.
Extract the object module that contains __purecall from the
LIBC.LIB library, and link the object explicitly. Using this
method, all other symbols in the object module will be included. To avoid
this potentially undesirable side-effect, the first method is recommended.
Microsoft Knowledge Base Q120919 ('Visual C++ Vers 2.0 README.WRI, Part 3
Compiler')