Article View: gnu.g++
Article #305Overloaded new operator in C++
From: User Jdsmith
Date: Thu, 15 Feb 1996 22:23
Date: Thu, 15 Feb 1996 22:23
32 lines
1459 bytes
1459 bytes
I am experiencing a problem with overloading the new operator when allocating an array of classes. I do the following and my overloaded new operator is called as expected: ptr = new ClassThatOverloadsNew; But when I do this: ptr = new ClassThatOverloadsNew[5]; The default new operator is called. What needs to be done to get an overloaded new operator to be called when allocating an array of data types? Does C++ even allow this to be done? I have checked several C++ manuals and none explicitely state that this can be done (and none say that it cannot be done!). I assumed that the overloaded new operator would be called with the number of bytes (the first parameter) being set to: sizeof(class) * arrayCount But this is not the case. Does anybody know how to solve this problem? I'm sure it is supported and is simple to do, I just have not found the right documentation on how to do it. My assumptions have been wrong so far, so I need some help. Thanks in advance, John Smith Systems Engineer, Electronic Data Systems
Technical Details
Message-ID:
<4g0boe$c37@maverick.tad.eds.com>Path:
arc1-ca.pugleaf.net!maverick.tad.eds.com!nemesis!venkatShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!maverick.tad.eds.com!nemesis!venkat From: venkat@nemesis.pln.rboc.eds.com (User Jdsmith) Newsgroups: gnu.g++,gnu.g++.help,comp.lang.c++ Subject: Overloaded new operator in C++ Date: 15 Feb 1996 22:23:10 GMT Organization: Somewhere in EDS... Message-ID: <4g0boe$c37@maverick.tad.eds.com> NNTP-Posting-Host: nemesis.pln.rboc.eds.com X-Newsreader: TIN [version 1.2 PL2]