+ Reply to Thread
Results 1 to 2 of 2

Thread: How to call explicit destructor in C++?

  1. #1

    How to call explicit destructor in C++?

    How to call explicit destructor in C++?

  2. #2
    Example:

    Code:
    class CPlacement
    {
    	int m_nValue ;
    public:
    	CPlacement(int nValue)
    	{
    		m_nValue = nValue;
    	}
    
    	~CPlacement()
    	{
    	}
    
    	int GetValue()
    	{
    		return m_nValue ;
    	}
    } ;
    
    void UsingPlacementNew()
    {
    	char *pPlacementMemory = (char *) malloc(sizeof(CPlacement)) ;
    
    	CPlacement *pPlacement = new (pPlacementMemory) CPlacement(10) ;
    
    	int nValue = pPlacement->GetValue() ;
    
    	pPlacement->~CPlacement() ;
    
    	free(pPlacementMemory) ;
    	pPlacementMemory = NULL ;
    
    	//no need of this...
    	//delete pPlacement ;
    }

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts