ID: Q115523
7.00 | 1.00 1.50 MS-DOS | WINDOWS kbtool kbbuglist
The information in this article applies to:
- Microsoft C/C++ for MS-DOS, version 7.0
- Microsoft Visual C++ for Windows, versions 1.0 and 1.5
In C++, it is not legal to overload operator delete within a class. However, when this is attempted, no specific error message is presented by the compiler informing the user of this limitation.
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
This is not a problem in the C/C++ 32-bit compiler, version 8.0 or version 9.0.
For reference, see "The Annotated C++ Reference Manual" by Ellis and Stroustrup, section 12.5: "Only one operator delete() may be declared for a single class; thus operator delete() cannot be overloaded. However, the Microsoft implementation of C++ extends this rule as stated in the 'C++ Language Reference' shipped with the product: 'For 16-bit targets, Microsoft C++ allows multiple delete operators to be present for a given class type--one for each data memory model.'"
The 32-bit C/C++, version 8.0, introduces the compiler error C2669, "illegal to overload member 'operator delete' with different number of formal arguments", which is generated in this situation.
// The following code should produce an error when compiling but
// does not. After removing the __near keywords, which are invalid
// for 32-bit compilers, the following code causes the C2669 error
// to occur when using the 32-bit compiler for Windows NT.
/* Compile options needed: /c
*/
#include <iostream.h>
#include <new.h>
class myClass
{
public:
void operator delete( void __near *ptr ) { ::delete(ptr); }
void operator delete( void __near *ptr, size_t mysize ) {
::delete(ptr); }
void PrintSomething() { cout << "In the class!" << endl; }
};
void main()
{
myClass * pTemp = new myClass;
pTemp->PrintSomething();
delete pTemp;
}
Last Reviewed: July 23, 1997