Mail Archives: djgpp/2000/02/09/06:18:02
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
- Raw text -