TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: SUNIR SHAH
from: DANIEL JONES
date: 1997-07-25 05:04:00
subject: Sunir ventures into

SS> Yes, but that requires an explicit cast or operation on the caller's
SS> so it isn't invisible.  By modifying the caller's variables without
SS> permission, the side effects could be disastrous.
SS> Say...
SS>     CFoo *pFoo = new CFoo;
SS>     EvilFooFunc( pFoo );
SS>     pFoo->member = ;
SS> void EvilFooFunc( CFoo* &pFoo )
SS> {
SS>     delete pFoo;
SS> }
SS> Can you say memory leak?
Sure. Now, consider this:
int FooCopy(CFoo *, CFoo *);
void EvilCFooFunc(CFoo *);
CFoo *pFoo = malloc(sizeof(CFoo));
EvilCFooFunc(pFoo);
FooCopy(pFoo, pAnotherFoo);
void EvilCFooFunc(CFoo *p)
{
    free p;
}
How are these two errors fundamentally different?  Both C and C++ will
cheefully stand by and watch as you shoot not only yourself but anyone
else in the immediate vicinity in the foot.  References provide a lot of
power, and aren't any more dangerous than many of C's capabilities.
You're just used to C's pitfalls, and don't think about them much
anymore.
Regards,
Daniel              ddjones@pinn.net
---
 þ RM 1.31 1604 þ Two's company, three's the result!
---------------
* Origin: Selective Source Virginia Beach, VA (757)471-6776 (1:275/102)

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™.