Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

Compiler Warning (level 1) C4291

Visual Studio 6.0

'declaration' : no matching operator delete found; memory will not be freed if initialization throws an exception

A placement new is used for which there is no placement delete.

You could reproduce this error by defining the following class in a global namespace:

typedef unsigned int size_t;

class MemBuffer_t {
public:
   void *Alloc(size_t);
};

MemBuffer_t memBuffer;

void *operator new(size_t size, MemBuffer_t &rBuffer)
{
   return rBuffer.Alloc(size);
}

class X {
public:
   X(int);
};

void f()
{
   X *pX = new (memBuffer) X(10);
}

This warning will only occur if the user compiles the code with /GX, exception handling enabled.

The fix for the warning is to declare and/or define the following operator delete after you define your operator new:

void operator delete(void *pMem, MemBuffer_t &rBuffer);
Show:
© 2015 Microsoft