Microsoft KB Archive/115523

{|
 * width="100%"|

BUG: No Error for Overloading Delete in a Class

 * }

Q115523

7.00 | 1.00 1.50 MS-DOS | WINDOWS kbtool kbbuglist -- The information in this article applies to: - The Microsoft C/C++ Compiler (CL.EXE) included with: - Microsoft C/C++ for MS-DOS, version 7.0 - Microsoft Visual C++ for Windows, versions 1.0 and 1.5 -- SYMPTOMS ======== 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. STATUS ====== 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. MORE INFORMATION ================ 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. Sample Code --- // 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 #include 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; } REFERENCES ========== - "The Annotated C++ Reference Manual" by Ellis and Stroustrup, section 12.5. - "C++ Language Reference," chapter 4, "Expressions, delete Operator." Additional reference words: 1.00 1.50 7.00 8.00 8.00c KBCategory: kbtool kbbuglist KBSubcategory: CPPIss

Keywords : kb16bitonly

Issue type : kbbug

Technology : kbVCsearch kbAudDeveloper kbCVCComp