_set_purecall_handler
TOC
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

_set_purecall_handler

Sets the handler for a pure virtual function call.

_purecall_handler _set_purecall_handler( 
   _purecall_handler function
);

Parameters

function
The function to be called when a pure virtual function is called. A _purecall_handler function should have a void return type.

Return Value

The previous _purecall_handler. Returns NULL if there was no previous handler.

Remarks

Use _set_purecall_handler if you want to catch pure virtual functions and report them to the user in a specific way or catch them for debugging purposes.

There is one _purecall_handler for the whole process, so calling this function will immediately impact all threads. The last caller on any thread will set the handler.

There is a single _set_purecall_handler handler for all dynamically linked DLLs or EXEs; even if you call _set_purecall_handler your handler may be replaced by another or that you are replacing a handler set by another DLL or EXE.

Requirements

Routine Required header Compatibility
_set_purecall_handler <stdlib.h> Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.

Libraries

All versions of the C run-time libraries.

Example

// _set_purecall_handler.cpp
// compile with: /W1
#include <tchar.h>
#include <stdio.h>
#include <stdlib.h>

class CDerived;
class CBase
{
public:
   CBase(CDerived *derived): m_pDerived(derived) {};
   ~CBase();
   virtual void function(void) = 0;

   CDerived * m_pDerived;
};

class CDerived : public CBase
{
public:
   CDerived() : CBase(this) {};   // C4355
   virtual void function(void) {};
};

CBase::~CBase()
{
   m_pDerived -> function();
}

void myPurecallHandler(void)
{
   printf("In _purecall_handler.");
   exit(0);
}

int _tmain(int argc, _TCHAR* argv[])
{
   _set_purecall_handler(myPurecallHandler);
   CDerived myDerived;
}

Output

In _purecall_handler.

See Also

Error Handling

Show:
© 2016 Microsoft