PRB: Errors Generated Overloading Operator New [] (122305)



The information in this article applies to:

  • Microsoft Visual C++ 1.0
  • Microsoft Visual C++ 1.5
  • Microsoft Visual C++ 1.51
  • Microsoft Visual C++ 1.52
  • Microsoft Visual C++ 2.0
  • Microsoft Visual C++ 4.0
  • Microsoft Visual C++ 4.1
  • Microsoft Visual C++, 32-bit Enterprise Edition 4.2
  • Microsoft Visual C++, 32-bit Enterprise Edition 5.0
  • Microsoft Visual C++, 32-bit Enterprise Edition 6.0
  • Microsoft Visual C++, 32-bit Professional Edition 4.2
  • Microsoft Visual C++, 32-bit Professional Edition 5.0
  • Microsoft Visual C++, 32-bit Professional Edition 6.0
  • Microsoft Visual C++, 32-bit Learning Edition 6.0

This article was previously published under Q122305

SYMPTOMS

The September 1994 ANSI C++ Draft specifies that it is possible to overload the new [] operator. However, the Microsoft C/C++ compilers included in the Microsoft products listed above do not support this feature. Microsoft C/C++ version 7.0 and Visual C++ up to version 5.0 will generate the following error message:
error C2092: array element type cannot be function
Microsoft Visual C++, 32-bit edition, version 5.0 generates two error messages:
error C2039: 'new[]' : is not a member of '`global namespace''

error C2660: 'new[]' : function does not take 1 parameters

STATUS

This behavior is by design.

MORE INFORMATION

The source code below can be used to illustrate how to overload the new [] operator, which will generate the error given above.

Sample Code to Reproduce Behavior

/* Compile options needed: none
*/ 

#include <new.h>

class example
{
public:

   void  *operator new [] ( size_t sz, const example& )
      { return( ::operator new [] ( sz )); }
};

void main(void)
{
}
				

Modification Type:MajorLast Reviewed:12/8/2003
Keywords:kbLangCPP kbprb KB122305