How to use the new operator from the Standard Library in Visual C++ (156808)
The information in this article applies to:
- The Standard C++ Library, when used with:
- 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 Q156808 SUMMARY The sample code below illustrates how to use the new
operator from the Standard Library in Visual C++. REFERENCES For more information about new operator, visit the following
Microsoft Developer Network (MSDN) Web site:
Note The Online Help for the new header file lists the
following prototypes for the new operators demonstrated in this article:
void *operator new(size_t n) throw(bad_alloc);
void *operator new(size_t n, const nothrow&) throw();
void *operator new[](size_t n) throw(bad_alloc);
The throw() following the prototype is an exception specification that
is not implemented in Visual C++ version 4.2. This is noted in the Online Help:
Microsoft C++ does not support the function exception
specification mechanism, as described in section 15.4 of the
ANSI C++ draft.
An exception-specification specifies the type of exceptions a
function can throw. For example,
void Func() throw (ProblemOne, ProblemTwo) {}
is equivalent to:
void Func() {
{
try {}
catch (ProblemOne) {}
catch (ProblemTwo) {}
catch (...) { unexpected(); }
}
Modification Type: | Major | Last Reviewed: | 7/13/2005 |
---|
Keywords: | kbhowto kbcode kbinfo KB156808 kbAudDeveloper |
---|
|