TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ALL
from: BALOG PAL
date: 1997-06-26 02:18:00
subject: Visual C++ 4.0 or MFC bug

I found another bug, and a serious one. :-(((
Just try:
CObject * foo = new CObject[4];   // any amount will do
delete [] foo;
The delete[] will trash the heap. In debug build you'll get an assert and a
chance to abort the program beore it goes to an access violation.
Any class derived from CObject will do the same. Other classes seem not.
Probably the bug is related to the fact CObject has an operator new and
delete pair.
Going to assembly one can see the delete will call the scalar delete instead
of the vector delete, just if you mistakenly tried to use the simple delete
on the array.
- ------------------------------------------
Another related question: CObject has no default callable ctors:
CObject * foo = new CObject;
will not compile as the only ctor is protected.
Then the question: is it legal to create an array as I did above? That
compiles without even a warning and that protected ctor is simply called.
Paul
... Remove cat from keyboard to continue.
--- OS/2 Warp
---------------
* Origin: The FlintStones' Cave in BedRock (2:371/20)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.