🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++
Article #306

Re: Overloaded new operator in C++

#306
From: Lars Toeffner-Clausen
Date: Mon, 19 Feb 1996 08:17
25 lines
1514 bytes
In article <4g0boe$c37@maverick.tad.eds.com> venkat@nemesis.pln.rboc.eds.com (User Jdsmith) writes:

> I am experiencing a problem with overloading the 
> new operator when allocating an array of classes.

You need two functions - which can also be defined on a per-class basis:

	void *operator new(size_t size);
	void *operator new[](size_t size);

> I assumed that the overloaded new operator would be called with the
> number of bytes (the first parameter) being set to:
> 
> sizeof(class) * arrayCount

This is true - also for the new[] operator.
-- 
"We need a plan to diverge from", Fesser
--
.---------------------------------------------------------.
| Lars Toeffner-Clausen         e-mail: lastec@dmi.min.dk |
| Oersted Science Data Center   Phone: +45 3915 7497      |
| Lyngbyvej 100                 Fax: +45 3915 7460        |
| DK - 2100 Koebenhavn Oe                                 |
`---------------------------------------------------------'
Technical Details
Message-ID: <LASTEC.96Feb19091713@karen.dmi.min.dk>
Path: arc1-ca.pugleaf.net!butler.dmi.min.dk!news!lastec
References: <4g0boe$c37@maverick.tad.eds.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!butler.dmi.min.dk!news!lastec
From: lastec@karen.dmi.min.dk (Lars Toeffner-Clausen)
Newsgroups: gnu.g++,gnu.g++.help,comp.lang.c++
Subject: Re: Overloaded new operator in C++
Date: 19 Feb 1996 08:17:13 GMT
Organization: Oersted Science Data Centre, Danish Meteorological Institute,
 Denmark
Message-ID: <LASTEC.96Feb19091713@karen.dmi.min.dk>
References: <4g0boe$c37@maverick.tad.eds.com>
NNTP-Posting-Host: karen.dmi.min.dk
In-reply-to: venkat@nemesis.pln.rboc.eds.com's message of 15 Feb 1996 22:23:10
 GMT