To: djgpp AT delorie DOT com Date: Wed, 09 Feb 2000 07:51:08 0000 From: "Nimrod Alonzo Abing" Message-ID: Mime-Version: 1.0 X-Sent-Mail: off X-Mailer: MailCity Service Subject: Overloading 'new []' and 'delete []' operators: How? X-Sender-Ip: 208.160.246.197 Organization: QUALCOMM Eudora Web-Mail (http://www.eudoramail.com:80) Content-Type: text/plain; charset=us-ascii Content-Language: en Content-Transfer-Encoding: 7bit Reply-To: djgpp AT delorie DOT com Hello! I have a question regarding C++ operator overloading, specifically the 'new []' and 'delete []' operators. In defining a class, I generally overload the 'new' and 'delete' operators whenever it is practical and the global 'new' and 'delete' operators won't do the job. It works fine for allocation of single class instances, but it breaks for arrays. An example below, overloads the 'new' and 'delete' operators for 'classname': -- code -- class classname { public: classname(); ~classname(); classname* operator new(size_t); void operator delete(); }; -- code -- Now this would work fine for: -- code -- classname *c; c = new classname; -- code -- Wherein the overloaded 'new' will be called instead of the global one. But the following does not call the overloaded 'new': -- code -- classname *c; c = new classname[10000]; -- code -- Q. Is there a way to call an overloaded version of 'new []' and its complementary operator 'delete []'? Do I have to overload them as well? How? Sensible answer will be greatly appreciated... oOOOo Synflood oOOOo --- Hot Windows Tip: ---------------- How to free up at least 300 MB of hard disk space (as seen from the MS-DOS prompt): C:\>deltree c:\windows Delete directory "Windows" and all its subdirectories? [yn] y Deleting Windows... C:\> Join 18 million Eudora users by signing up for a free Eudora Web-Mail account at http://www.eudoramail.com